Skip to content

Commit e09512a

Browse files
Daniel Baileykorelstar
Daniel Bailey
authored andcommitted
Remove unnecessary if/else statement
Removed bool test of isInitialised. Small change to manifest.
1 parent 426103b commit e09512a

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
android:parentActivityName="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity"
7878
/>
7979

80+
<activity
81+
android:name="it.niedermann.owncloud.notes.android.activity.SelectSingleNoteActivity">
82+
83+
<intent-filter>
84+
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
85+
</intent-filter>
86+
</activity>
87+
8088
<receiver
8189
android:name=".android.activity.CreateNoteWidget"
8290
android:label="@string/widget_create_note">
@@ -103,13 +111,5 @@
103111
android:name="android.appwidget.provider"
104112
android:resource="@xml/single_note_widget_provider_info" />
105113
</receiver>
106-
107-
<activity
108-
android:name="it.niedermann.owncloud.notes.android.activity.SelectSingleNoteActivity">
109-
110-
<intent-filter>
111-
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
112-
</intent-filter>
113-
</activity>
114114
</application>
115115
</manifest>

app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public void onNoteClick(int position, View v) {
7171
SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(this).edit();
7272

7373
sp.putLong(SingleNoteWidget.WIDGET_KEY + mAppWidgetId, noteID);
74-
sp.putBoolean(SingleNoteWidget.WIDGET_KEY + mAppWidgetId + SingleNoteWidget.INIT, true);
7574
sp.apply();
7675

7776
Intent retIntent = new Intent(this, SingleNoteWidget.class);

app/src/main/java/it/niedermann/owncloud/notes/android/activity/SingleNoteWidget.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
public class SingleNoteWidget extends AppWidgetProvider {
2121

2222
public static final String WIDGET_KEY = "single_note_widget";
23-
public static final String INIT = "INIT";
2423
private static final String TAG = SingleNoteWidget.class.getSimpleName();
2524

2625
@Override
@@ -35,34 +34,26 @@ public void onDeleted(Context context, int[] appWidgetIds) {
3534
SharedPreferences.Editor sharedprefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
3635

3736
for (int appWidgetId : appWidgetIds) {
38-
Log.d(TAG, "Removing " + WIDGET_KEY + appWidgetId + " from sharedprefs");
39-
Log.d(TAG, "Removing " + WIDGET_KEY + appWidgetId + INIT + " from sharedprefs");
4037
sharedprefs.remove(WIDGET_KEY + appWidgetId);
41-
sharedprefs.remove(WIDGET_KEY + appWidgetId + INIT);
4238
}
4339
sharedprefs.apply();
4440
}
4541

4642
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
47-
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(context);
4843
SharedPreferences sharedprefs = PreferenceManager.getDefaultSharedPreferences(context);
4944
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_single_note);
5045
long noteID = sharedprefs.getLong(SingleNoteWidget.WIDGET_KEY + appWidgetId, -1);
51-
boolean isInitialised = sharedprefs.getBoolean(SingleNoteWidget.WIDGET_KEY + appWidgetId + INIT, false);
5246

5347
if (noteID >= 0) {
54-
if (isInitialised) {
55-
DBNote note = db.getNote(noteID);
56-
Intent intent = new Intent(context, EditNoteActivity.class);
57-
intent.putExtra(EditNoteActivity.PARAM_NOTE, note);
58-
intent.putExtra(EditNoteActivity.PARAM_WIDGET_SRC, true);
59-
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
60-
views.setOnClickPendingIntent(R.id.widget_single_note, pendingIntent);
61-
views.setTextViewText(R.id.single_note_content, note.getContent());
62-
appWidgetManager.updateAppWidget(appWidgetId, views);
63-
} else {
64-
Log.e(TAG, "Widget not initialised");
65-
}
48+
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(context);
49+
DBNote note = db.getNote(noteID);
50+
Intent intent = new Intent(context, EditNoteActivity.class);
51+
intent.putExtra(EditNoteActivity.PARAM_NOTE, note);
52+
intent.putExtra(EditNoteActivity.PARAM_WIDGET_SRC, true);
53+
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
54+
views.setOnClickPendingIntent(R.id.widget_single_note, pendingIntent);
55+
views.setTextViewText(R.id.single_note_content, note.getContent());
56+
appWidgetManager.updateAppWidget(appWidgetId, views);
6657
} else {
6758
Log.e(TAG, "Note not found");
6859
views.setTextViewText(R.id.single_note_content, "Note not found");

0 commit comments

Comments
 (0)