Commit ceaf6dd4 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Branding for NoteListWidget

parent 51d9513b
......@@ -6,6 +6,7 @@ import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.util.Log;
import android.widget.RemoteViews;
......@@ -16,7 +17,9 @@ import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.android.DarkModeSetting;
import it.niedermann.owncloud.notes.android.activity.EditNoteActivity;
import it.niedermann.owncloud.notes.android.activity.NotesListViewActivity;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.model.Category;
import it.niedermann.owncloud.notes.model.LocalAccount;
import it.niedermann.owncloud.notes.model.NoteListsWidgetData;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.util.Notes;
......@@ -42,6 +45,7 @@ public class NoteListWidget extends AppWidgetProvider {
for (int appWidgetId : appWidgetIds) {
try {
final NoteListsWidgetData data = db.getNoteListWidgetData(appWidgetId);
final LocalAccount localAccount = db.getAccount(data.getAccountId());
String category = null;
if (data.getCategoryId() != null) {
......@@ -61,7 +65,7 @@ public class NoteListWidget extends AppWidgetProvider {
// Open the main app if the user taps the widget header
PendingIntent openAppI = PendingIntent.getActivity(context, PENDING_INTENT_OPEN_APP_RQ,
intent,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Launch create note activity if user taps "+" icon on header
......@@ -85,6 +89,17 @@ public class NoteListWidget extends AppWidgetProvider {
views.setRemoteAdapter(appWidgetId, R.id.note_list_widget_lv_dark, serviceIntent);
views.setEmptyView(R.id.note_list_widget_lv_dark, R.id.widget_note_list_placeholder_tv_dark);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.note_list_widget_lv_dark);
if (BrandingUtil.isBrandingEnabled(context)) {
views.setInt(R.id.widget_note_header_dark, "setBackgroundColor", localAccount.getColor());
views.setInt(R.id.widget_note_header_icon_dark, "setColorFilter", localAccount.getTextColor());
views.setInt(R.id.widget_note_list_create_icon_dark, "setColorFilter", localAccount.getTextColor());
views.setTextColor(R.id.widget_note_list_title_tv_dark, localAccount.getTextColor());
} else {
views.setInt(R.id.widget_note_header_dark, "setBackgroundColor", context.getResources().getColor(R.color.defaultBrand));
views.setInt(R.id.widget_note_header_icon_dark, "setColorFilter", Color.WHITE);
views.setInt(R.id.widget_note_list_create_icon_dark, "setColorFilter", Color.WHITE);
views.setTextColor(R.id.widget_note_list_title_tv_dark, Color.WHITE);
}
} else {
views = new RemoteViews(context.getPackageName(), R.layout.widget_note_list);
views.setTextViewText(R.id.widget_note_list_title_tv, getWidgetTitle(context, data.getMode(), category));
......@@ -95,6 +110,17 @@ public class NoteListWidget extends AppWidgetProvider {
views.setRemoteAdapter(appWidgetId, R.id.note_list_widget_lv, serviceIntent);
views.setEmptyView(R.id.note_list_widget_lv, R.id.widget_note_list_placeholder_tv);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.note_list_widget_lv);
if (BrandingUtil.isBrandingEnabled(context)) {
views.setInt(R.id.widget_note_header, "setBackgroundColor", localAccount.getColor());
views.setInt(R.id.widget_note_header_icon, "setColorFilter", localAccount.getTextColor());
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", localAccount.getTextColor());
views.setTextColor(R.id.widget_note_list_title_tv, localAccount.getTextColor());
} else {
views.setInt(R.id.widget_note_header, "setBackgroundColor", context.getResources().getColor(R.color.defaultBrand));
views.setInt(R.id.widget_note_header_icon, "setColorFilter", Color.WHITE);
views.setInt(R.id.widget_note_list_create_icon, "setColorFilter", Color.WHITE);
views.setTextColor(R.id.widget_note_list_title_tv, Color.WHITE);
}
}
awm.updateAppWidget(appWidgetId, views);
......@@ -158,4 +184,11 @@ public class NoteListWidget extends AppWidgetProvider {
return null;
}
}
/**
* Update note list widgets, if the note data was changed.
*/
public static void updateNoteListWidgets(Context context) {
context.sendBroadcast(new Intent(context, NoteListWidget.class).setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE));
}
}
......@@ -87,4 +87,11 @@ public class SingleNoteWidget extends AppWidgetProvider {
}
super.onDeleted(context, appWidgetIds);
}
/**
* Update single note widget, if the note data was changed.
*/
public static void updateSingleNoteWidgets(Context context) {
context.sendBroadcast(new Intent(context, SingleNoteWidget.class).setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE));
}
}
......@@ -20,6 +20,8 @@ import it.niedermann.owncloud.notes.persistence.SyncWorker;
import it.niedermann.owncloud.notes.util.DeviceCredentialUtil;
import it.niedermann.owncloud.notes.util.Notes;
import static it.niedermann.owncloud.notes.android.appwidget.NoteListWidget.updateNoteListWidgets;
public class PreferencesFragment extends PreferenceFragmentCompat implements Branded {
private static final String TAG = PreferencesFragment.class.getSimpleName();
......@@ -43,6 +45,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
brandingPref = findPreference(getString(R.string.pref_key_branding));
if (brandingPref != null) {
brandingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
updateNoteListWidgets(requireContext());
final Boolean branding = (Boolean) newValue;
Log.v(TAG, "branding: " + branding);
requireActivity().setResult(Activity.RESULT_OK);
......@@ -57,7 +60,12 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
if (lockPref != null) {
if (!DeviceCredentialUtil.areCredentialsAvailable(requireContext())) {
lockPref.setVisible(false);
findPreference(getString(R.string.pref_category_security)).setVisible(false);
Preference securityCategory = findPreference(getString(R.string.pref_category_security));
if (securityCategory != null) {
securityCategory.setVisible(false);
} else {
Log.e(TAG, "Could not find preference " + getString(R.string.pref_category_security));
}
} else {
lockPref.setOnPreferenceChangeListener((preference, newValue) -> {
Notes.setLockedPreference((Boolean) newValue);
......
......@@ -57,6 +57,8 @@ import it.niedermann.owncloud.notes.util.ColorUtil;
import it.niedermann.owncloud.notes.util.NoteUtil;
import static it.niedermann.owncloud.notes.android.activity.EditNoteActivity.ACTION_SHORTCUT;
import static it.niedermann.owncloud.notes.android.appwidget.NoteListWidget.updateNoteListWidgets;
import static it.niedermann.owncloud.notes.android.appwidget.SingleNoteWidget.updateSingleNoteWidgets;
import static it.niedermann.owncloud.notes.model.NoteListsWidgetData.MODE_DISPLAY_CATEGORY;
/**
......@@ -682,24 +684,6 @@ public class NotesDatabase extends AbstractNotesDatabase {
}).start();
}
/**
* Update single note widget, if the note data was changed.
*/
private static void updateSingleNoteWidgets(Context context) {
Intent intent = new Intent(context, SingleNoteWidget.class);
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
context.sendBroadcast(intent);
}
/**
* Update note list widgets, if the note data was changed.
*/
private static void updateNoteListWidgets(Context context) {
Intent intent = new Intent(context, NoteListWidget.class);
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
context.sendBroadcast(intent);
}
public boolean hasAccounts() {
return DatabaseUtils.queryNumEntries(getReadableDatabase(), table_accounts) > 0;
}
......
......@@ -8,9 +8,10 @@
<!-- Widget header -->
<RelativeLayout
android:id="@+id/widget_note_header"
android:layout_width="match_parent"
android:layout_height="@dimen/widget_note_list_header_height"
android:background="@drawable/ic_launcher_background"
android:background="@color/defaultBrand"
android:padding="@dimen/widget_note_list_hdr_padding">
<ImageView
......
......@@ -9,6 +9,7 @@
<!-- Widget header -->
<RelativeLayout
android:id="@+id/widget_note_header_dark"
android:layout_width="match_parent"
android:layout_height="@dimen/widget_note_list_header_height"
android:background="@drawable/ic_launcher_background"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment