Commit aa5a7742 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch 'Issue-2829' into 'master'

2829-P,Q-Dark mode implementation

See merge request e/apps/notes!20
parents f358b394 965df19e
Pipeline #120470 passed with stage
in 3 minutes and 23 seconds
......@@ -60,6 +60,7 @@
android:name="foundation.e.notes.android.activity.EditNoteActivity"
android:label="@string/simple_edit"
android:launchMode="singleTask"
android:theme="@style/Preferences"
android:parentActivityName="foundation.e.notes.android.activity.NotesListViewActivity"
android:windowSoftInputMode="stateHidden">
<intent-filter android:label="@string/action_create">
......@@ -79,6 +80,7 @@
<activity
android:name="foundation.e.notes.android.activity.AboutActivity"
android:label="@string/simple_about"
android:theme="@style/Preferences"
android:parentActivityName="foundation.e.notes.android.activity.NotesListViewActivity" />
<activity
android:name="foundation.e.notes.android.activity.SelectSingleNoteActivity"
......
......@@ -44,6 +44,7 @@ import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.ItemTouchHelper;
......@@ -341,7 +342,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
drawerToggle.setHomeAsUpIndicator(lineageos.platform.R.drawable.ic_hamburger);
if (toolbar.getNavigationIcon() != null)
toolbar.getNavigationIcon().setTint(getResources().getColor(lineageos.platform.R.color.color_default_accent));
toolbar.getNavigationIcon().setTint(ContextCompat.getColor(this, lineageos.platform.R.color.color_default_accent));
drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
......@@ -753,6 +754,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == create_note_cmd) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
......
......@@ -72,7 +72,6 @@ public class SelectSingleNoteActivity extends NotesListViewActivity {
SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(this).edit();
sp.putLong(SingleNoteWidget.WIDGET_KEY + appWidgetId, noteID);
sp.putBoolean(SingleNoteWidget.DARK_THEME_KEY + appWidgetId, Notes.getAppTheme(getApplicationContext()));
sp.apply();
Intent updateIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null,
......
......@@ -15,11 +15,11 @@ import android.widget.RemoteViews;
import foundation.e.notes.android.activity.EditNoteActivity;
import foundation.e.notes.android.activity.NotesListViewActivity;
import foundation.e.notes.R;
import foundation.e.notes.util.Notes;
public class NoteListWidget extends AppWidgetProvider {
public static final String WIDGET_MODE_KEY = "NLW_mode";
public static final String WIDGET_CATEGORY_KEY = "NLW_cat";
public static final String DARK_THEME_KEY = "NLW_darkTheme";
public static final int NLW_DISPLAY_ALL = 0;
public static final int NLW_DISPLAY_STARRED = 1;
public static final int NLW_DISPLAY_CATEGORY = 2;
......@@ -38,12 +38,11 @@ public class NoteListWidget extends AppWidgetProvider {
}
String category = sp.getString(NoteListWidget.WIDGET_CATEGORY_KEY + appWidgetId, null);
darkTheme = sp.getBoolean(NoteListWidget.DARK_THEME_KEY + appWidgetId, false);
darkTheme = Notes.getAppTheme(context);
Intent serviceIntent = new Intent(context, NoteListWidgetService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
serviceIntent.putExtra(NoteListWidget.WIDGET_MODE_KEY + appWidgetId, displayMode);
serviceIntent.putExtra(NoteListWidget.DARK_THEME_KEY + appWidgetId, darkTheme);
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
if (displayMode == NLW_DISPLAY_CATEGORY) {
......@@ -131,7 +130,6 @@ public class NoteListWidget extends AppWidgetProvider {
for (int appWidgetId : appWidgetIds) {
editor.remove(WIDGET_MODE_KEY + appWidgetId);
editor.remove(WIDGET_CATEGORY_KEY + appWidgetId);
editor.remove(DARK_THEME_KEY + appWidgetId);
}
editor.apply();
......
......@@ -4,23 +4,17 @@ import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -29,13 +23,6 @@ import foundation.e.notes.android.activity.NotesListViewActivity;
import foundation.e.notes.model.NavigationAdapter;
import foundation.e.notes.persistence.NoteSQLiteOpenHelper;
import foundation.e.notes.persistence.NoteServerSyncHelper;
import foundation.e.notes.util.Notes;
import foundation.e.notes.R;
import foundation.e.notes.android.activity.NotesListViewActivity;
import foundation.e.notes.model.NavigationAdapter;
import foundation.e.notes.persistence.NoteSQLiteOpenHelper;
import foundation.e.notes.persistence.NoteServerSyncHelper;
import foundation.e.notes.util.Notes;
public class NoteListWidgetConfiguration extends AppCompatActivity {
private static final String TAG = Activity.class.getSimpleName();
......@@ -101,8 +88,6 @@ public class NoteListWidgetConfiguration extends AppCompatActivity {
sp.putInt(NoteListWidget.WIDGET_MODE_KEY + appWidgetId, NoteListWidget.NLW_DISPLAY_CATEGORY);
sp.putString(NoteListWidget.WIDGET_CATEGORY_KEY + appWidgetId, category);
}
sp.putBoolean(NoteListWidget.DARK_THEME_KEY + appWidgetId, Notes.getAppTheme(getApplicationContext()));
sp.apply();
Intent updateIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null,
......
......@@ -16,6 +16,7 @@ import foundation.e.notes.R;
import foundation.e.notes.android.activity.EditNoteActivity;
import foundation.e.notes.model.DBNote;
import foundation.e.notes.persistence.NoteSQLiteOpenHelper;
import foundation.e.notes.util.Notes;
public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
private final Context context;
......@@ -33,7 +34,7 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
AppWidgetManager.INVALID_APPWIDGET_ID);
sp = PreferenceManager.getDefaultSharedPreferences(this.context);
displayMode = sp.getInt(NoteListWidget.WIDGET_MODE_KEY + appWidgetId, -1);
darkTheme = sp.getBoolean(NoteListWidget.DARK_THEME_KEY + appWidgetId, false);
darkTheme = Notes.getAppTheme(this.context);
category = sp.getString(NoteListWidget.WIDGET_CATEGORY_KEY + appWidgetId, "");
}
......
......@@ -11,13 +11,13 @@ import android.net.Uri;
import android.preference.PreferenceManager;
import android.widget.RemoteViews;
import foundation.e.notes.android.activity.EditNoteActivity;
import foundation.e.notes.R;
import foundation.e.notes.android.activity.EditNoteActivity;
import foundation.e.notes.util.Notes;
public class SingleNoteWidget extends AppWidgetProvider {
private static boolean darkTheme;
public static final String DARK_THEME_KEY = "SNW_darkTheme";
public static final String WIDGET_KEY = "single_note_widget";
static void updateAppWidget(Context context, AppWidgetManager awm, int[] appWidgetIds) {
......@@ -31,10 +31,10 @@ public class SingleNoteWidget extends AppWidgetProvider {
return;
}
darkTheme = sp.getBoolean(DARK_THEME_KEY + appWidgetId, false);
darkTheme = Notes.getAppTheme(context);
PendingIntent templatePendingIntent = PendingIntent.getActivity(context, appWidgetId, templateIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.FLAG_UPDATE_CURRENT);
Intent serviceIntent = new Intent(context, SingleNoteWidgetService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
......@@ -47,7 +47,7 @@ public class SingleNoteWidget extends AppWidgetProvider {
views.setPendingIntentTemplate(foundation.e.notes.R.id.single_note_widget_lv_dark, templatePendingIntent);
views.setRemoteAdapter(foundation.e.notes.R.id.single_note_widget_lv_dark, serviceIntent);
views.setEmptyView(foundation.e.notes.R.id.single_note_widget_lv_dark, foundation.e.notes.R.id.widget_single_note_placeholder_tv_dark);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv_dark);
awm.notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv_dark);
} else {
views = new RemoteViews(context.getPackageName(), foundation.e.notes.R.layout.widget_single_note);
views.setPendingIntentTemplate(foundation.e.notes.R.id.single_note_widget_lv, templatePendingIntent);
......@@ -72,7 +72,7 @@ public class SingleNoteWidget extends AppWidgetProvider {
AppWidgetManager awm = AppWidgetManager.getInstance(context);
updateAppWidget(context, AppWidgetManager.getInstance(context),
(awm.getAppWidgetIds(new ComponentName(context, SingleNoteWidget.class))));
(awm.getAppWidgetIds(new ComponentName(context, SingleNoteWidget.class))));
}
@Override
......@@ -82,7 +82,6 @@ public class SingleNoteWidget extends AppWidgetProvider {
for (int appWidgetId : appWidgetIds) {
editor.remove(WIDGET_KEY + appWidgetId);
editor.remove(NoteListWidget.DARK_THEME_KEY + appWidgetId);
}
editor.apply();
......
......@@ -18,6 +18,7 @@ import foundation.e.notes.android.activity.EditNoteActivity;
import foundation.e.notes.model.DBNote;
import foundation.e.notes.persistence.NoteSQLiteOpenHelper;
import foundation.e.notes.util.MarkDownUtil;
import foundation.e.notes.util.Notes;
public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
......@@ -35,9 +36,9 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa
SingleNoteWidgetFactory(Context context, Intent intent) {
this.context = context;
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
AppWidgetManager.INVALID_APPWIDGET_ID);
sp = PreferenceManager.getDefaultSharedPreferences(this.context);
darkTheme = sp.getBoolean(SingleNoteWidget.DARK_THEME_KEY + appWidgetId, false);
darkTheme = Notes.getAppTheme(this.context);
markdownProcessor = new MarkdownProcessor(this.context);
markdownProcessor.factory(TextFactory.create());
markdownProcessor.config(MarkDownUtil.getMarkDownConfiguration(this.context, darkTheme).build());
......
......@@ -149,7 +149,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
private void colorWithText(String newText) {
if (activeTextView != null && ViewCompat.isAttachedToWindow(activeTextView)) {
activeTextView.setText(DisplayUtils.searchAndColor(activeTextView.getText().toString(), new SpannableString
(activeTextView.getText()), newText, getResources().getColor(R.color.primary)),
(activeTextView.getText()), newText, getResources().getColor(R.color.color_default_primary_text)),
TextView.BufferType.SPANNABLE);
}
}
......
......@@ -26,15 +26,6 @@ public class PreferencesFragment extends PreferenceFragment {
return true;
});
final SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.pref_key_theme));
themePref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
Boolean darkTheme = (Boolean) newValue;
Notes.setAppTheme(darkTheme);
getActivity().setResult(Activity.RESULT_OK);
getActivity().recreate();
return true;
});
final SwitchPreference wifiOnlyPref = (SwitchPreference) findPreference(getString(R.string.pref_key_wifi_only));
wifiOnlyPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
Boolean syncOnWifiOnly = (Boolean) newValue;
......
package foundation.e.notes.model;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
......@@ -95,14 +95,14 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
count.setVisibility(item.count == null ? View.GONE : View.VISIBLE);
count.setText(String.valueOf(item.count));
if (item.icon > 0) {
icon.setImageDrawable(icon.getResources().getDrawable(item.icon));
icon.setImageDrawable(ContextCompat.getDrawable(icon.getContext(), item.icon));
icon.setVisibility(View.VISIBLE);
} else {
icon.setVisibility(View.GONE);
}
view.setBackgroundColor(isSelected ? ColorUtils.setAlphaComponent(view.getResources().getColor(R.color.accent_color),20) : Color.TRANSPARENT);
int textColor = view.getResources().getColor(isSelected ? R.color.accent_color : R.color.fg_default);
int unSelectedIconColor = view.getResources().getColor(isSelected ? R.color.accent_color : R.color.drawer_menu_icon_color);
view.setBackgroundColor(isSelected ? ColorUtils.setAlphaComponent(view.getResources().getColor(R.color.accent_color), 20) : Color.TRANSPARENT);
int textColor = ContextCompat.getColor(view.getContext(), isSelected ? R.color.accent_color : R.color.color_default_primary_text);
int unSelectedIconColor = ContextCompat.getColor(view.getContext(), isSelected ? R.color.accent_color : R.color.drawer_menu_icon_color);
name.setTextColor(textColor);
count.setTextColor(textColor);
......
......@@ -11,6 +11,7 @@ import android.text.style.ForegroundColorSpan;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import androidx.core.content.ContextCompat;
import java.util.ArrayList;
import java.util.Calendar;
......@@ -57,7 +58,7 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
SpannableString spannableString = new SpannableString(dbNote.getTitle());
Matcher matcher = Pattern.compile("(" + searchQuery + ")", Pattern.CASE_INSENSITIVE).matcher(spannableString);
while (matcher.find()) {
spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(foundation.e.notes.R.color.primary_dark)),
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, foundation.e.notes.R.color.light_grey)),
matcher.start(), matcher.end(), 0);
}
......@@ -66,7 +67,7 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
spannableString = new SpannableString(dbNote.getExcerpt());
matcher = Pattern.compile("(" + searchQuery + ")", Pattern.CASE_INSENSITIVE).matcher(spannableString);
while (matcher.find()) {
spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(foundation.e.notes.R.color.primary_dark)),
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, foundation.e.notes.R.color.light_grey)),
matcher.start(), matcher.end(), 0);
}
......
......@@ -24,15 +24,15 @@ public class MarkDownUtil {
*/
public static Builder getMarkDownConfiguration(Context context) {
return new RxMDConfiguration.Builder(context)
.setUnOrderListColor(ContextCompat.getColor(context, R.color.fg_default))
.setCodeBgColor(ContextCompat.getColor(context, R.color.fg_default_high))
.setUnOrderListColor(ContextCompat.getColor(context, R.color.color_default_secondary_text))
.setCodeBgColor(ContextCompat.getColor(context, R.color.color_default_primary_text))
.setHeader2RelativeSize(1.35f)
.setHeader3RelativeSize(1.25f)
.setHeader4RelativeSize(1.15f)
.setHeader5RelativeSize(1.1f)
.setHeader6RelativeSize(1.05f)
.setHorizontalRulesHeight(2)
.setLinkFontColor(ContextCompat.getColor(context, R.color.primary));
.setLinkFontColor(ContextCompat.getColor(context, R.color.color_default_primary_text));
}
public static Builder getMarkDownConfiguration(Context context, Boolean darkTheme) {
......@@ -45,6 +45,6 @@ public class MarkDownUtil {
.setHeader5RelativeSize(1.1f)
.setHeader6RelativeSize(1.05f)
.setHorizontalRulesHeight(2)
.setLinkFontColor(ResourcesCompat.getColor(context.getResources(), R.color.primary, null));
.setLinkFontColor(ResourcesCompat.getColor(context.getResources(), R.color.color_default_primary_text, null));
}
}
......@@ -2,29 +2,12 @@ package foundation.e.notes.util;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.appcompat.app.AppCompatDelegate;
import android.content.res.Configuration;
public class Notes extends Application {
private static final String DARK_THEME = "darkTheme";
@Override
public void onCreate() {
setAppTheme(getAppTheme(getApplicationContext()));
super.onCreate();
}
public static void setAppTheme(Boolean darkTheme) {
if (darkTheme) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
public static boolean getAppTheme(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(DARK_THEME, false);
int nightModeFlags = context.getApplicationContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
return nightModeFlags == Configuration.UI_MODE_NIGHT_YES;
}
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Selector is used for Background Colors in List Items -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- :selected -->
<item android:color="@color/fg_default_low" android:state_enabled="false" />
<item android:color="@color/fg_default" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><!-- Selector is used for Background Colors in List Items -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- :selected -->
<item android:color="@color/fg_default_high" android:state_enabled="false" />
<item android:color="@color/fg_contrast" />
<item android:color="@color/color_default_secondary_text" android:state_enabled="false" />
<item android:color="@color/color_default_primary_text" />
</selector>
\ No newline at end of file
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#0082C9" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF0082C9" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
<path android:fillColor="@color/accent_color" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@color/accent_color"
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?><!-- Selector is used for Background Colors in List Items -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- :selected -->
<item android:drawable="@color/bg_highlighted" android:state_selected="true" />
<item android:drawable="@color/fg_default" android:state_selected="true" />
<item android:drawable="@color/bg_normal" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><!-- Selector is used for Header Color in List Items -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- :selected -->
<item android:color="@color/fg_default_selection" android:state_activated="true" />
<item android:color="@color/fg_default" />
<item android:color="@color/color_default_primary_text" android:state_activated="true" />
<item android:color="@color/color_default_secondary_text" />
</selector>
\ No newline at end of file
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