Skip to content

Commit aa1b350

Browse files
committed
Minor fixes and improvements to the stability. Release version 1.10.
1 parent e4f6100 commit aa1b350

31 files changed

Lines changed: 234 additions & 330 deletions

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
minSdkVersion 17
1010
targetSdkVersion 33
1111
// targetSdkPreview "Tiramisu"
12-
versionCode 11
13-
versionName "1.0.9"
12+
versionCode 12
13+
versionName "1.0.10"
1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515
}
1616
buildTypes {

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
77
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
8-
<uses-permission
9-
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
10-
tools:ignore="ScopedStorage" />
118
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
129
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1310

app/src/main/java/de/nilsfo/lockscreennotes/LockScreenNotes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.nilsfo.lockscreennotes;
22

3-
import android.app.Activity;
43
import android.app.Application;
54
import android.content.Context;
65
import android.content.Intent;

app/src/main/java/de/nilsfo/lockscreennotes/activity/EditNoteActivity.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
import android.widget.TextView;
2020
import android.widget.Toast;
2121

22+
import androidx.appcompat.app.ActionBar;
23+
import androidx.appcompat.app.AlertDialog;
24+
import androidx.core.app.NavUtils;
25+
import androidx.core.content.FileProvider;
26+
2227
import com.google.android.material.snackbar.Snackbar;
2328

2429
import java.io.File;
2530
import java.io.FileOutputStream;
2631
import java.io.IOException;
2732
import java.util.Date;
2833

29-
import androidx.appcompat.app.ActionBar;
30-
import androidx.appcompat.app.AlertDialog;
31-
import androidx.core.app.NavUtils;
32-
import androidx.core.content.FileProvider;
3334
import de.nilsfo.lockscreennotes.LockScreenNotes;
3435
import de.nilsfo.lockscreennotes.data.Note;
3536
import de.nilsfo.lockscreennotes.data.content.NoteContentAnalyzer;
@@ -43,7 +44,6 @@
4344
import de.nilsfo.lsn.R;
4445
import timber.log.Timber;
4546

46-
4747
public class EditNoteActivity extends NotesActivity {
4848

4949
public static final String EXTRA_NOTE_ACTIVITY_NOTE_ID = LockScreenNotes.APP_TAG + "EditNoteActivity_note_id";
@@ -95,6 +95,10 @@ protected void onCreate(Bundle savedInstanceState) {
9595
handleIllegalNote();
9696
return;
9797
}
98+
if (myNote == null) {
99+
handleIllegalNote();
100+
return;
101+
}
98102

99103
setShowNotifications(true);
100104
noteTF = (EditText) findViewById(R.id.enditNoteFullscreenTF);

app/src/main/java/de/nilsfo/lockscreennotes/activity/MainActivity.java

Lines changed: 47 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package de.nilsfo.lockscreennotes.activity;
22

3+
import static de.nilsfo.lockscreennotes.LockScreenNotes.PREFS_TAG;
4+
import static de.nilsfo.lockscreennotes.LockScreenNotes.REQUEST_CODE_INTENT_EXTERNAL_SEARCH;
5+
36
import android.app.Activity;
47
import android.content.DialogInterface;
58
import android.content.Intent;
69
import android.content.SharedPreferences;
710
import android.content.res.Configuration;
811
import android.net.Uri;
9-
import android.os.Build;
1012
import android.os.Bundle;
1113
import android.preference.PreferenceManager;
1214
import android.text.TextUtils;
@@ -20,6 +22,11 @@
2022
import android.widget.TextView;
2123
import android.widget.Toast;
2224

25+
import androidx.annotation.NonNull;
26+
import androidx.appcompat.app.AlertDialog;
27+
import androidx.recyclerview.widget.LinearLayoutManager;
28+
import androidx.recyclerview.widget.RecyclerView;
29+
2330
import com.google.android.material.floatingactionbutton.FloatingActionButton;
2431
import com.google.android.material.snackbar.Snackbar;
2532
import com.skydoves.balloon.ArrowOrientation;
@@ -45,11 +52,6 @@
4552
import java.util.concurrent.ExecutorService;
4653
import java.util.concurrent.Executors;
4754

48-
import androidx.annotation.NonNull;
49-
import androidx.appcompat.app.AlertDialog;
50-
import androidx.recyclerview.widget.LinearLayoutManager;
51-
import androidx.recyclerview.widget.RecyclerView;
52-
5355
import de.nilsfo.lockscreennotes.LockScreenNotes;
5456
import de.nilsfo.lockscreennotes.data.Note;
5557
import de.nilsfo.lockscreennotes.data.RelativeTimeTextfieldContainer;
@@ -69,10 +71,6 @@
6971
import de.nilsfo.lsn.R;
7072
import timber.log.Timber;
7173

72-
import static de.nilsfo.lockscreennotes.LockScreenNotes.PREFS_TAG;
73-
import static de.nilsfo.lockscreennotes.LockScreenNotes.REQUEST_CODE_INTENT_EXTERNAL_SEARCH;
74-
import static de.nilsfo.lockscreennotes.io.StoragePermissionManager.StoragePermissionState.STATE_MEDIA_ONLY;
75-
7674
public class MainActivity extends NotesActivity implements Observer, NotesRecyclerAdapter.NotesRecyclerAdapterListener {
7775

7876
public static final int IMPORT_NOTE_PREVIEW_SIZE = 35;
@@ -85,7 +83,7 @@ public class MainActivity extends NotesActivity implements Observer, NotesRecycl
8583
private NotesRecyclerAdapter noteRecyclerAdapter;
8684
private RecyclerView notesRecyclerView;
8785
private ScrollView tutorialView;
88-
private CheckBox tutorialDontShowAgainCB;
86+
private CheckBox tutorialDoNotShowAgainCB;
8987
private TextView nothingToDisplayLB;
9088
private ExecutorService executorService;
9189

@@ -102,8 +100,8 @@ protected void onCreate(Bundle savedInstanceState) {
102100
tutorialView = (ScrollView) findViewById(R.id.tutorial_view);
103101
nothingToDisplayLB = (TextView) findViewById(R.id.nothing_to_display);
104102

105-
tutorialDontShowAgainCB = (CheckBox) findViewById(R.id.tutorial_do_not_show_again_cb);
106-
tutorialDontShowAgainCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
103+
tutorialDoNotShowAgainCB = (CheckBox) findViewById(R.id.tutorial_do_not_show_again_cb);
104+
tutorialDoNotShowAgainCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
107105
@Override
108106
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
109107
onTutorialCBclicked(isChecked);
@@ -190,6 +188,11 @@ public void requestRecoverNote(Note note) {
190188

191189
public void requestDeleteNote(long databaseID) {
192190
final Note note = Note.getNoteFromDB(databaseID, databaseAdapter);
191+
if (note == null) {
192+
Toast.makeText(this, R.string.error_internal_error, Toast.LENGTH_LONG).show();
193+
return;
194+
}
195+
193196
Timber.i("Request to delete note: '" + note.getText() + "'");
194197
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("prefs_quick_delete", true)) {
195198
deleteNote(note.getDatabaseID());
@@ -325,65 +328,10 @@ private void reviewNotificationPermissions() {
325328
return;
326329
}
327330

328-
if (storagePermissionManager.getPermissionState() == STATE_MEDIA_ONLY) {
329-
// The item is visible because the user needs to update their storage permissions
330-
showPermissionDialogStorageUpgrade();
331-
return;
332-
}
333-
334331
// All permissions granted.
335332
Toast.makeText(this, R.string.info_review_notification_permissions_granted, Toast.LENGTH_LONG).show();
336333
}
337334

338-
public void showPermissionDialogStorageUpgrade() {
339-
NotesNotificationManager notesNotificationManager = new NotesNotificationManager(this);
340-
final Activity activity = this;
341-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
342-
// The user's device is too old. This should not affect them!
343-
Toast.makeText(activity, R.string.action_review_storage_upgrade_permissions_wrong_version, Toast.LENGTH_LONG).show();
344-
return;
345-
}
346-
347-
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
348-
builder.setTitle(R.string.action_review_storage_upgrade_permissions);
349-
builder.setIcon(R.mipmap.ic_launcher);
350-
builder.setMessage(getString(R.string.action_review_storage_upgrade_permissions_info));
351-
352-
builder.setNeutralButton(R.string.prefs_review_notifications_settings_system_title, new DialogInterface.OnClickListener() {
353-
@Override
354-
public void onClick(DialogInterface dialog, int which) {
355-
dialog.dismiss();
356-
try {
357-
Intent intent = LockScreenNotes.BuildPermissionIntentSystemSettings(activity);
358-
startActivity(intent);
359-
} catch (Exception e) {
360-
Timber.e(e);
361-
Toast.makeText(activity, R.string.error_internal_error, Toast.LENGTH_LONG).show();
362-
}
363-
}
364-
});
365-
builder.setPositiveButton(R.string.action_review_storage_upgrade_permissions_enable_permissions, new DialogInterface.OnClickListener() {
366-
@Override
367-
public void onClick(DialogInterface dialog, int which) {
368-
dialog.dismiss();
369-
StoragePermissionManager storagePermissionManager = new StoragePermissionManager(activity);
370-
try {
371-
storagePermissionManager.requestExternalStoragePermission(activity);
372-
} catch (Exception e) {
373-
Timber.e(e);
374-
Toast.makeText(activity, R.string.error_internal_error, Toast.LENGTH_LONG).show();
375-
}
376-
}
377-
});
378-
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
379-
@Override
380-
public void onClick(DialogInterface dialog, int which) {
381-
dialog.cancel();
382-
}
383-
});
384-
builder.show();
385-
}
386-
387335
public void showPermissionDialogNotification() {
388336
NotesNotificationManager notesNotificationManager = new NotesNotificationManager(this);
389337
final Activity activity = this;
@@ -454,27 +402,14 @@ private void hidePermissionBalloon() {
454402
}
455403
}
456404

457-
private void requestExtendStoragePermissionsDialog() {
458-
// TODO implement
459-
}
460-
461405
private void requestBackupMenu() {
462406
BackupManager backupManager = new BackupManager(this);
463407
StoragePermissionManager storagePermissionManager = new StoragePermissionManager(this);
464-
StoragePermissionManager.StoragePermissionState currentState = storagePermissionManager.getPermissionState();
465-
boolean storageManager = storagePermissionManager.isExternalStorageManager();
466-
Timber.i("Current permission state: " + currentState);
467-
Timber.i("Is storage manager: " + storageManager);
468-
469-
// Checking if permissions are granted, but need upgrading
470-
if (storagePermissionManager.requiresExtendedPermissions() && !storagePermissionManager.hasPermissionsTotallyDenied()) {
471-
Toast.makeText(this, R.string.error_external_permissions_require_upgrade, Toast.LENGTH_LONG).show();
472-
requestExtendStoragePermissionsDialog();
473-
return;
474-
}
408+
boolean hasExternalStoragePermission = storagePermissionManager.hasExternalStoragePermission();
409+
Timber.i("Has external Storage Permission: " + hasExternalStoragePermission);
475410

476411
// Checking if external permissions are granted
477-
if (!storagePermissionManager.hasAllCorrectPermissions()) {
412+
if (!hasExternalStoragePermission) {
478413
Toast.makeText(this, R.string.warning_no_storage_permission, Toast.LENGTH_LONG).show();
479414
storagePermissionManager.requestExternalStoragePermission(this);
480415
return;
@@ -918,12 +853,6 @@ private void updateNotificationPermissionMenuItem() {
918853
Timber.i("Setting the permission item to visible, because NO NOTIFICATION PERMISSIONS");
919854
checkAppPermissionItem.setVisible(true);
920855
}
921-
922-
if (storagePermissionManager.getPermissionState() == STATE_MEDIA_ONLY) {
923-
// The item is visible because the user needs to update their storage permissions
924-
Timber.i("Setting the permission item to visible, because STORAGE PERMISSION UPDATE NEEDED");
925-
checkAppPermissionItem.setVisible(true);
926-
}
927856
}
928857

929858
private void requestDisplayPermissionBalloon() {
@@ -1022,21 +951,41 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1022951
Uri uri = data.getData();
1023952
Timber.i("File Uri: " + uri.toString());
1024953
String path = null;
954+
boolean fileSelectionSuccess = true;
1025955
try {
1026956
path = new FileManager(this).getPath(uri);
1027957
Timber.i("File Path: " + path);
1028958
} catch (URISyntaxException e) {
1029959
e.printStackTrace();
1030960
Timber.e(e);
1031-
return;
961+
fileSelectionSuccess = false;
1032962
}
1033-
try {
1034-
requestBackupImportMenuConfirmFile(new File(path));
1035-
} catch (Exception e) {
1036-
e.printStackTrace();
1037-
Timber.e(e);
1038-
Toast.makeText(this, R.string.error_invalid_file_format, Toast.LENGTH_LONG).show();
963+
964+
if (!fileSelectionSuccess) {
965+
// TOOD handle this
966+
}
967+
968+
if (path == null && fileSelectionSuccess) {
969+
// Path is null. Looks like the file was not found?
970+
Timber.e("Error! The file path is NULL!");
971+
//TODO handle this!
972+
break;
973+
}
974+
975+
if (fileSelectionSuccess) {
976+
try {
977+
requestBackupImportMenuConfirmFile(new File(path));
978+
} catch (Exception e) {
979+
e.printStackTrace();
980+
Timber.e(e);
981+
Toast.makeText(this, R.string.error_invalid_file_format, Toast.LENGTH_LONG).show();
982+
}
983+
} else {
984+
// File selector failed
985+
// TODO Handle this
1039986
}
987+
} else {
988+
// TODO what if not OK?
1040989
}
1041990
break;
1042991
}
@@ -1139,7 +1088,7 @@ protected void onResume() {
11391088
databaseAdapter.open();
11401089
loadNotesFromDB();
11411090

1142-
tutorialDontShowAgainCB.setChecked(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PREFS_HIDE_TUTORIAL, false));
1091+
tutorialDoNotShowAgainCB.setChecked(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PREFS_HIDE_TUTORIAL, false));
11431092
setupRelativeDateUpdater();
11441093

11451094
Timber.i("MainActivity: onResume()");

app/src/main/java/de/nilsfo/lockscreennotes/activity/NotesActivity.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package de.nilsfo.lockscreennotes.activity;
22

3-
import android.content.BroadcastReceiver;
4-
import android.content.Context;
5-
import android.content.Intent;
6-
73
import androidx.appcompat.app.AppCompatActivity;
84

9-
import java.util.Locale;
10-
115
/**
126
* Created by Nils on 16.08.2016.
137
*/

app/src/main/java/de/nilsfo/lockscreennotes/activity/NotificationDeleteRecieverDialogActivity.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import android.content.DialogInterface;
55
import android.content.Intent;
66
import android.os.Bundle;
7+
import android.widget.Toast;
8+
9+
import androidx.appcompat.app.AlertDialog;
710

811
import java.util.ArrayList;
912

10-
import androidx.appcompat.app.AlertDialog;
1113
import de.nilsfo.lockscreennotes.data.Note;
1214
import de.nilsfo.lockscreennotes.sql.DBAdapter;
1315
import de.nilsfo.lockscreennotes.util.NotesNotificationManager;
@@ -36,11 +38,23 @@ protected void onCreate(Bundle savedInstanceState) {
3638
Timber.i("That was no known ID, so just hide them all.");
3739
} else {
3840
Note note = Note.getNoteFromDB(notificationId, databaseAdapter);
39-
notes.add(note);
40-
Timber.i("Found the right note with matching ID in the database.");
41+
if (note != null) {
42+
notes.add(note);
43+
Timber.i("Found the right note with matching ID in the database.");
44+
} else {
45+
Timber.e("Failed to get note from DB with ID: " + notificationId);
46+
}
4147
}
4248
databaseAdapter.close();
4349

50+
if (notes.isEmpty()) {
51+
// ERROR: Notes to be deleted are empty!
52+
Timber.e("Cannot delete notes! None found!");
53+
Toast.makeText(this, R.string.error_internal_error, Toast.LENGTH_LONG)
54+
.show();
55+
return;
56+
}
57+
4458
String msgText;
4559
if (notes.size() == 1) {
4660
msgText = String.format(getString(R.string.delete_dialog_content), notes.get(0).getTextPreview());

0 commit comments

Comments
 (0)