Skip to content

Commit

Permalink
changes due to code review
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Oct 29, 2019
1 parent 3de5e8f commit c1aa005
Show file tree
Hide file tree
Showing 31 changed files with 258 additions and 113 deletions.
2 changes: 2 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected void onCreate(Bundle savedInstanceState) {
});

Button providerButton = findViewById(R.id.signup);
providerButton.setBackgroundColor(getResources().getColor(R.color.primary));
providerButton.setBackgroundColor(getResources().getColor(R.color.primary_dark));
providerButton.setTextColor(getResources().getColor(R.color.login_text_color));
providerButton.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
providerButton.setOnClickListener(v -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public final class AppPreferencesImpl implements AppPreferences {
private static final String PREF__AUTO_UPLOAD_INIT = "autoUploadInit";
private static final String PREF__FOLDER_SORT_ORDER = "folder_sort_order";
private static final String PREF__FOLDER_LAYOUT = "folder_layout";
public static final String PREF__THEME = "darkTheme";

private static final String PREF__DARK_THEME = "darkTheme";
private static final String PREF__LOCK_TIMESTAMP = "lock_timestamp";
private static final String PREF__SHOW_MEDIA_SCAN_NOTIFICATIONS = "show_media_scan_notifications";
private static final String PREF__LOCK = SettingsActivity.PREFERENCE_LOCK;
Expand Down Expand Up @@ -344,7 +344,7 @@ public int getUploaderBehaviour() {

@Override
public boolean isDarkThemeEnabled() {
return preferences.getBoolean(PREF__DARK_THEME, false);
return preferences.getBoolean(PREF__THEME, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,8 @@ private static Bitmap handlePNG(Bitmap bitmap, int pxW, int pxH) {
Bitmap resultBitmap = Bitmap.createBitmap(pxW, pxH, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(resultBitmap);

c.drawColor(MainApp.getAppContext().getResources().getColor(R.color.bg_default));
// TODO check based on https://github.com/nextcloud/android/pull/3459#discussion_r339935975
c.drawColor(MainApp.getAppContext().getResources().getColor(R.color.background_color_png));
c.drawBitmap(bitmap, 0, 0, null);

return resultBitmap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ private void findSwitch(ViewGroup viewGroup) {
new int[][]{new int[]{android.R.attr.state_checked},
new int[]{}},
new int[]{trackColor, trackColorUnchecked});
// new int[]{trackColor, Color.parseColor("#4D000000")});
}

// setting the thumb color
Expand Down
55 changes: 29 additions & 26 deletions src/main/java/com/owncloud/android/ui/activity/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
Expand All @@ -27,29 +28,32 @@
/**
* Base activity with common behaviour for activities dealing with ownCloud {@link Account}s .
*/
public abstract class BaseActivity extends AppCompatActivity implements Injectable, SharedPreferences.OnSharedPreferenceChangeListener {
public abstract class BaseActivity
extends AppCompatActivity
implements Injectable, SharedPreferences.OnSharedPreferenceChangeListener {

private static final String TAG = BaseActivity.class.getSimpleName();

/**
* ownCloud {@link Account} where the main {@link OCFile} handled by the activity is located.
*/
private Account mCurrentAccount;
private Account currentAccount;

/**
* Capabilities of the server where {@link #mCurrentAccount} lives.
* Capabilities of the server where {@link #currentAccount} lives.
*/
private OCCapability mCapabilities;
private OCCapability capabilities;

/**
* Access point to the cached database for the current ownCloud {@link Account}.
*/
private FileDataStorageManager mStorageManager;
private FileDataStorageManager storageManager;

/**
* Tracks whether the activity should be recreate()'d after a theme change
*/
private boolean mThemeChangePending;
private boolean mPaused;
private boolean themeChangePending;
private boolean paused;

@Inject UserAccountManager accountManager;
@Inject SharedPreferences sharedPreferences;
Expand All @@ -73,16 +77,15 @@ protected void onDestroy() {
@Override
protected void onPause() {
super.onPause();
mPaused = true;
paused = true;
}

@Override
protected void onResume() {
super.onResume();
mPaused = false;
paused = false;

if(mThemeChangePending) {
// getDelegate().applyDayNight();
if(themeChangePending) {
recreate();
}
}
Expand All @@ -98,8 +101,8 @@ protected void onNewIntent(Intent intent) {

Log_OC.v(TAG, "onNewIntent() start");
Account current = accountManager.getCurrentAccount();
if (current != null && mCurrentAccount != null && !mCurrentAccount.name.equals(current.name)) {
mCurrentAccount = current;
if (current != null && currentAccount != null && !currentAccount.name.equals(current.name)) {
currentAccount = current;
}
Log_OC.v(TAG, "onNewIntent() stop");
}
Expand All @@ -112,7 +115,7 @@ protected void onNewIntent(Intent intent) {
protected void onRestart() {
Log_OC.v(TAG, "onRestart() start");
super.onRestart();
boolean validAccount = mCurrentAccount != null && accountManager.exists(mCurrentAccount);
boolean validAccount = currentAccount != null && accountManager.exists(currentAccount);
if (!validAccount) {
swapToDefaultAccount();
}
Expand All @@ -121,12 +124,12 @@ protected void onRestart() {

@Override
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
if (!getString(R.string.prefs_key_theme).equals(key)) {
if (!AppPreferencesImpl.PREF__THEME.equals(key)) {
return;
}

if(mPaused) {
mThemeChangePending = true;
if(paused) {
themeChangePending = true;
return;
}
recreate();
Expand All @@ -144,7 +147,7 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
protected void setAccount(Account account, boolean savedAccount) {
boolean validAccount = account != null && accountManager.setCurrentOwnCloudAccount(account.name);
if (validAccount) {
mCurrentAccount = account;
currentAccount = account;
} else {
swapToDefaultAccount();
}
Expand All @@ -163,7 +166,7 @@ protected void swapToDefaultAccount() {
/// no account available: force account creation
createAccount(true);
} else {
mCurrentAccount = newAccount;
currentAccount = newAccount;
}
}

Expand Down Expand Up @@ -192,16 +195,16 @@ protected void createAccount(boolean mandatoryCreation) {
@Deprecated
protected void onAccountSet() {
if (getAccount() != null) {
mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
mCapabilities = mStorageManager.getCapability(mCurrentAccount.name);
storageManager = new FileDataStorageManager(getAccount(), getContentResolver());
capabilities = storageManager.getCapability(currentAccount.name);
} else {
Log_OC.e(TAG, "onAccountChanged was called with NULL account associated!");
}
}

@Deprecated
protected void setAccount(Account account) {
mCurrentAccount = account;
currentAccount = account;
}

/**
Expand All @@ -211,7 +214,7 @@ protected void setAccount(Account account) {
* set yet.
*/
public OCCapability getCapabilities() {
return mCapabilities;
return capabilities;
}

/**
Expand All @@ -222,20 +225,20 @@ public OCCapability getCapabilities() {
* is located.
*/
public Account getAccount() {
return mCurrentAccount;
return currentAccount;
}

@Override
protected void onStart() {
super.onStart();

if(mCurrentAccount != null) {
if(currentAccount != null) {
onAccountSet();
}
}

public FileDataStorageManager getStorageManager() {
return mStorageManager;
return storageManager;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,12 +991,17 @@ protected void setDrawerMenuItemChecked(int menuItemId) {
MenuItem menuItem = mNavigationView.getMenu().getItem(i);
if (menuItem.getIcon() != null) {
menuItem.getIcon().clearColorFilter();
if(menuItem.getGroupId() != R.id.drawer_menu_accounts
if (menuItem.getGroupId() != R.id.drawer_menu_accounts
|| menuItem.getItemId() == R.id.drawer_menu_account_add
|| menuItem.getItemId() == R.id.drawer_menu_account_manage) {
ThemeUtils.tintDrawable(menuItem.getIcon(), ContextCompat.getColor(this, R.color.drawer_menu_icon));
ThemeUtils.tintDrawable(
menuItem.getIcon(), ContextCompat.getColor(this, R.color.drawer_menu_icon));
}
menuItem.setTitle(Html.fromHtml("<font color='" + ThemeUtils.colorToHexString(ContextCompat.getColor(this, R.color.textColor)) + "'>" + menuItem.getTitle() + "</font>"));
menuItem.setTitle(Html.fromHtml(
"<font color='"
+ ThemeUtils.colorToHexString(ContextCompat.getColor(this, R.color.textColor))
+ "'>" + menuItem.getTitle()
+ "</font>"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
Expand Down Expand Up @@ -693,13 +692,12 @@ private void setupGeneralCategory(int accentColor) {

loadStoragePath();

SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.prefs_key_theme));
SwitchPreference themePref = (SwitchPreference) findPreference(AppPreferencesImpl.PREF__THEME);

themePref.setSummary(preferences.isDarkThemeEnabled() ?
getString(R.string.prefs_value_theme_dark) : getString(R.string.prefs_value_theme_light));
themePref.setOnPreferenceChangeListener((preference, newValue) -> {
MainApp.setAppTheme((Boolean) newValue);
// recreate();

return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.ui.activity;
Expand All @@ -28,12 +28,15 @@

import androidx.annotation.Nullable;

public class ThemedPreferenceActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
public class ThemedPreferenceActivity
extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {

/**
* Tracks whether the activity should be recreate()'d after a theme change
*/
private boolean mThemeChangePending;
private boolean mPaused;
private boolean themeChangePending;
private boolean paused;

@Inject SharedPreferences sharedPreferences;

Expand All @@ -52,23 +55,23 @@ protected void onDestroy() {
@Override
protected void onPause() {
super.onPause();
mPaused = true;
paused = true;
}

@Override
protected void onResume() {
super.onResume();
mPaused = false;
paused = false;

if(mThemeChangePending) {
if(themeChangePending) {
recreate();
}
}

@Override
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
if(mPaused) {
mThemeChangePending = true;
if(paused) {
themeChangePending = true;
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,12 @@ public void updateDrawState(@NonNull TextPaint ds) {
}
}, idx1, idx2, 0);
ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), idx1, idx2, 0);
ssb.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.textColor)),
idx1, idx2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(
new ForegroundColorSpan(context.getResources().getColor(R.color.textColor)),
idx1,
idx2,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
}
idx1 = text.indexOf('{', idx2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.PictureDrawable;
import android.net.Uri;
Expand Down Expand Up @@ -87,7 +85,8 @@ public NotificationListAdapter(OwnCloudClient client, NotificationsActivity noti
this.notificationsList = new ArrayList<>();
this.client = client;
this.notificationsActivity = notificationsActivity;
foregroundColorSpanBlack = new ForegroundColorSpan(notificationsActivity.getResources().getColor(R.color.textColor));
foregroundColorSpanBlack = new ForegroundColorSpan(
notificationsActivity.getResources().getColor(R.color.textColor));
}

public void setNotificationItems(List<Notification> notificationItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,9 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
searchView.setOnCloseListener(this);
ThemeUtils.themeSearchView(searchView, true, requireContext());


SearchView.SearchAutoComplete theTextArea = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);
SearchView.SearchAutoComplete theTextArea = searchView.findViewById(R.id.search_src_text);
theTextArea.setHighlightColor(ThemeUtils.primaryAccentColor(getContext()));

// EditText searchText = searchView.findViewById(R.id.searchView);
// searchText.setHighlightColor(ThemeUtils.primaryColor(getContext(), true));

final Handler handler = new Handler();

DisplayMetrics displaymetrics = new DisplayMetrics();
Expand Down
Loading

0 comments on commit c1aa005

Please sign in to comment.