Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
Notes
Commits
c3debd3d
Commit
c3debd3d
authored
Apr 01, 2021
by
Stefan Niedermann
Browse files
Remove branding toggle
parent
5944fbac
Changes
12
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedActivity.java
View file @
c3debd3d
...
...
@@ -37,11 +37,9 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand
getTheme
().
resolveAttribute
(
R
.
attr
.
colorAccent
,
typedValue
,
true
);
colorAccent
=
typedValue
.
data
;
if
(
BrandingUtil
.
isBrandingEnabled
(
this
))
{
@ColorInt
final
int
mainColor
=
BrandingUtil
.
readBrandMainColor
(
this
);
@ColorInt
final
int
textColor
=
BrandingUtil
.
readBrandTextColor
(
this
);
applyBrand
(
mainColor
,
textColor
);
}
@ColorInt
final
int
mainColor
=
BrandingUtil
.
readBrandMainColor
(
this
);
@ColorInt
final
int
textColor
=
BrandingUtil
.
readBrandTextColor
(
this
);
applyBrand
(
mainColor
,
textColor
);
}
@Override
...
...
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedDialogFragment.java
View file @
c3debd3d
...
...
@@ -14,11 +14,9 @@ public abstract class BrandedDialogFragment extends DialogFragment implements Br
@Nullable
Context
context
=
getContext
();
if
(
context
!=
null
)
{
if
(
BrandingUtil
.
isBrandingEnabled
(
context
))
{
@ColorInt
final
int
mainColor
=
BrandingUtil
.
readBrandMainColor
(
context
);
@ColorInt
final
int
textColor
=
BrandingUtil
.
readBrandTextColor
(
context
);
applyBrand
(
mainColor
,
textColor
);
}
@ColorInt
final
int
mainColor
=
BrandingUtil
.
readBrandMainColor
(
context
);
@ColorInt
final
int
textColor
=
BrandingUtil
.
readBrandTextColor
(
context
);
applyBrand
(
mainColor
,
textColor
);
}
}
}
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedFragment.java
View file @
c3debd3d
...
...
@@ -32,7 +32,7 @@ public abstract class BrandedFragment extends Fragment implements Branded {
colorPrimary
=
typedValue
.
data
;
@Nullable
Context
context
=
getContext
();
if
(
context
!=
null
&&
BrandingUtil
.
isBrandingEnabled
(
context
)
)
{
if
(
context
!=
null
)
{
@ColorInt
final
int
mainColor
=
BrandingUtil
.
readBrandMainColor
(
context
);
@ColorInt
final
int
textColor
=
BrandingUtil
.
readBrandTextColor
(
context
);
applyBrand
(
mainColor
,
textColor
);
...
...
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedPreferenceCategory.java
View file @
c3debd3d
...
...
@@ -34,13 +34,11 @@ public class BrandedPreferenceCategory extends PreferenceCategory {
public
void
onBindViewHolder
(
PreferenceViewHolder
holder
)
{
super
.
onBindViewHolder
(
holder
);
if
(
BrandingUtil
.
isBrandingEnabled
(
getContext
()))
{
final
View
v
=
holder
.
itemView
.
findViewById
(
android
.
R
.
id
.
title
);
@Nullable
final
Context
context
=
getContext
();
if
(
context
!=
null
&&
v
instanceof
TextView
)
{
@ColorInt
final
int
mainColor
=
getSecondaryForegroundColorDependingOnTheme
(
context
,
BrandingUtil
.
readBrandMainColor
(
context
));
((
TextView
)
v
).
setTextColor
(
mainColor
);
}
final
View
v
=
holder
.
itemView
.
findViewById
(
android
.
R
.
id
.
title
);
@Nullable
final
Context
context
=
getContext
();
if
(
context
!=
null
&&
v
instanceof
TextView
)
{
@ColorInt
final
int
mainColor
=
getSecondaryForegroundColorDependingOnTheme
(
context
,
BrandingUtil
.
readBrandMainColor
(
context
));
((
TextView
)
v
).
setTextColor
(
mainColor
);
}
}
}
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSnackbar.java
View file @
c3debd3d
...
...
@@ -15,10 +15,8 @@ public class BrandedSnackbar {
@NonNull
public
static
Snackbar
make
(
@NonNull
View
view
,
@NonNull
CharSequence
text
,
@Snackbar
.
Duration
int
duration
)
{
final
Snackbar
snackbar
=
Snackbar
.
make
(
view
,
text
,
duration
);
if
(
BrandingUtil
.
isBrandingEnabled
(
view
.
getContext
()))
{
int
color
=
BrandingUtil
.
readBrandMainColor
(
view
.
getContext
());
snackbar
.
setActionTextColor
(
ColorUtil
.
INSTANCE
.
isColorDark
(
color
)
?
Color
.
WHITE
:
color
);
}
final
int
color
=
BrandingUtil
.
readBrandMainColor
(
view
.
getContext
());
snackbar
.
setActionTextColor
(
ColorUtil
.
INSTANCE
.
isColorDark
(
color
)
?
Color
.
WHITE
:
color
);
return
snackbar
;
}
...
...
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSwitchPreference.java
View file @
c3debd3d
...
...
@@ -61,13 +61,8 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded
@Override
public
void
applyBrand
(
@ColorInt
int
mainColor
,
@ColorInt
int
textColor
)
{
if
(
BrandingUtil
.
isBrandingEnabled
(
getContext
()))
{
this
.
mainColor
=
mainColor
;
this
.
textColor
=
textColor
;
}
else
{
this
.
mainColor
=
getContext
().
getResources
().
getColor
(
R
.
color
.
defaultBrand
);
this
.
textColor
=
Color
.
WHITE
;
}
this
.
mainColor
=
mainColor
;
this
.
textColor
=
textColor
;
// onBindViewHolder is called after applyBrand, therefore we have to store the given values and apply them later.
applyBrand
();
}
...
...
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java
View file @
c3debd3d
...
...
@@ -33,43 +33,30 @@ public class BrandingUtil {
}
public
static
boolean
isBrandingEnabled
(
@NonNull
Context
context
)
{
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
);
return
prefs
.
getBoolean
(
context
.
getString
(
R
.
string
.
pref_key_branding
),
true
);
}
@ColorInt
public
static
int
readBrandMainColor
(
@NonNull
Context
context
)
{
if
(
BrandingUtil
.
isBrandingEnabled
(
context
))
{
SharedPreferences
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
.
getApplicationContext
());
Log
.
v
(
TAG
,
"--- Read: shared_preference_theme_main"
);
return
sharedPreferences
.
getInt
(
pref_key_branding_main
,
context
.
getApplicationContext
().
getResources
().
getColor
(
R
.
color
.
defaultBrand
));
}
else
{
return
ContextCompat
.
getColor
(
context
,
R
.
color
.
defaultBrand
);
}
final
SharedPreferences
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
.
getApplicationContext
());
Log
.
v
(
TAG
,
"--- Read: shared_preference_theme_main"
);
return
sharedPreferences
.
getInt
(
pref_key_branding_main
,
context
.
getApplicationContext
().
getResources
().
getColor
(
R
.
color
.
defaultBrand
));
}
@ColorInt
public
static
int
readBrandTextColor
(
@NonNull
Context
context
)
{
if
(
isBrandingEnabled
(
context
))
{
SharedPreferences
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
.
getApplicationContext
());
Log
.
v
(
TAG
,
"--- Read: shared_preference_theme_text"
);
return
sharedPreferences
.
getInt
(
pref_key_branding_text
,
Color
.
WHITE
);
}
else
{
return
Color
.
WHITE
;
}
final
SharedPreferences
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
.
getApplicationContext
());
Log
.
v
(
TAG
,
"--- Read: shared_preference_theme_text"
);
return
sharedPreferences
.
getInt
(
pref_key_branding_text
,
Color
.
WHITE
);
}
public
static
void
saveBrandColors
(
@NonNull
Context
context
,
@ColorInt
int
mainColor
,
@ColorInt
int
textColor
)
{
final
int
previousMainColor
=
readBrandMainColor
(
context
);
final
int
previousTextColor
=
readBrandTextColor
(
context
);
SharedPreferences
.
Editor
editor
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
).
edit
();
final
SharedPreferences
.
Editor
editor
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
).
edit
();
Log
.
v
(
TAG
,
"--- Write: shared_preference_theme_main"
+
" | "
+
mainColor
);
Log
.
v
(
TAG
,
"--- Write: shared_preference_theme_text"
+
" | "
+
textColor
);
editor
.
putInt
(
pref_key_branding_main
,
mainColor
);
editor
.
putInt
(
pref_key_branding_text
,
textColor
);
editor
.
apply
();
if
(
isBrandingEnabled
(
context
)
&&
context
instanceof
BrandedActivity
)
{
if
(
context
instanceof
BrandedActivity
)
{
if
(
mainColor
!=
previousMainColor
||
textColor
!=
previousTextColor
)
{
final
BrandedActivity
activity
=
(
BrandedActivity
)
context
;
activity
.
runOnUiThread
(()
->
ActivityCompat
.
recreate
(
activity
));
...
...
app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java
View file @
c3debd3d
...
...
@@ -16,6 +16,7 @@ import it.niedermann.owncloud.notes.persistence.migration.Migration_15_16;
import
it.niedermann.owncloud.notes.persistence.migration.Migration_16_17
;
import
it.niedermann.owncloud.notes.persistence.migration.Migration_17_18
;
import
it.niedermann.owncloud.notes.persistence.migration.Migration_18_19
;
import
it.niedermann.owncloud.notes.persistence.migration.Migration_19_20
;
import
it.niedermann.owncloud.notes.persistence.migration.Migration_4_5
;
import
it.niedermann.owncloud.notes.persistence.migration.Migration_5_6
;
import
it.niedermann.owncloud.notes.persistence.migration.Migration_6_7
;
...
...
@@ -26,7 +27,7 @@ import it.niedermann.owncloud.notes.shared.util.DatabaseIndexUtil;
abstract
class
AbstractNotesDatabase
extends
SQLiteOpenHelper
{
private
static
final
int
database_version
=
19
;
private
static
final
int
database_version
=
20
;
@NonNull
protected
final
Context
context
;
...
...
@@ -194,6 +195,8 @@ abstract class AbstractNotesDatabase extends SQLiteOpenHelper {
new
Migration_17_18
(
db
);
case
18
:
new
Migration_18_19
(
context
);
case
19
:
new
Migration_19_20
(
context
);
}
}
...
...
app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java
0 → 100644
View file @
c3debd3d
package
it.niedermann.owncloud.notes.persistence.migration
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
androidx.annotation.NonNull
;
import
androidx.preference.PreferenceManager
;
public
class
Migration_19_20
{
/**
* Removes <code>branding</code> from {@link SharedPreferences} because we do no longer allow to disable it.
*
* @param context {@link Context}
*/
public
Migration_19_20
(
@NonNull
Context
context
)
{
PreferenceManager
.
getDefaultSharedPreferences
(
context
).
edit
().
remove
(
"branding"
).
apply
();
}
}
app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java
View file @
c3debd3d
...
...
@@ -44,20 +44,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
fontPref
=
findPreference
(
getString
(
R
.
string
.
pref_key_font
));
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
);
ActivityCompat
.
recreate
(
requireActivity
());
return
true
;
});
}
else
{
Log
.
e
(
TAG
,
"Could not find preference with key: \""
+
getString
(
R
.
string
.
pref_key_branding
)
+
"\""
);
}
gridViewPref
=
findPreference
(
getString
(
R
.
string
.
pref_key_gridview
));
if
(
gridViewPref
!=
null
)
{
gridViewPref
.
setOnPreferenceChangeListener
((
Preference
preference
,
Object
newValue
)
->
{
...
...
app/src/main/res/values/strings.xml
View file @
c3debd3d
...
...
@@ -99,7 +99,6 @@
<string
name=
"pref_key_note_mode"
translatable=
"false"
>
noteMode
</string>
<string
name=
"pref_key_theme"
translatable=
"false"
>
darkTheme
</string>
<string
name=
"pref_key_font"
translatable=
"false"
>
font
</string>
<string
name=
"pref_key_branding"
translatable=
"false"
>
branding
</string>
<string
name=
"pref_key_gridview"
translatable=
"false"
>
gridview
</string>
<string
name=
"pref_key_font_size"
translatable=
"false"
>
fontSize
</string>
<string
name=
"pref_key_wifi_only"
translatable=
"false"
>
wifiOnly
</string>
...
...
app/src/main/res/xml/preferences.xml
View file @
c3debd3d
...
...
@@ -38,13 +38,6 @@
android:summary=
"%s"
android:title=
"@string/settings_theme_title"
/>
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
android:defaultValue=
"true"
android:icon=
"@drawable/ic_color_lens_grey600_24dp"
android:key=
"@string/pref_key_branding"
android:layout=
"@layout/item_pref"
android:title=
"@string/settings_branding"
/>
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
android:icon=
"@drawable/ic_baseline_dashboard_24"
android:key=
"@string/pref_key_gridview"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment