Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
5728644
Styling More preference
tonyr59h Nov 24, 2015
fa05c8d
Removing divider between list and buttons in DetailListPreference dialog
tonyr59h Nov 25, 2015
6b4bc30
Fixing lint error
tonyr59h Nov 25, 2015
faa074d
Fixing edit text preference styling
tonyr59h Nov 30, 2015
eb06bc6
Removing dividers in number picker
tonyr59h Nov 30, 2015
5a54497
Adjusting fonts on Related Posts dialog
tonyr59h Dec 1, 2015
a9b9df7
Adding dividers to related posts dialog
tonyr59h Dec 1, 2015
64c4b32
Padding empty view
tonyr59h Dec 1, 2015
912d836
Creating utility class to handle common functions
tonyr59h Dec 1, 2015
ce97891
Adjusting layout of related posts dialog to match design
tonyr59h Dec 2, 2015
30a58e1
Matching design with list editor input dialog
tonyr59h Dec 2, 2015
92f38bb
Toggling background color for checked items in action mode
tonyr59h Dec 3, 2015
2cb682e
Paging and close after settings no longer show pre-defined values
tonyr59h Dec 4, 2015
8c5e13b
Using reflection to style number picker view
tonyr59h Dec 5, 2015
171c55a
Improving number alignment for center number
tonyr59h Dec 5, 2015
bfc16e2
Drawing 5 items in the number picker scroller, no fading edges
tonyr59h Dec 7, 2015
713ae1f
Changing to number pickers for close after and paging settings
tonyr59h Dec 7, 2015
708f463
Merge branch 'feature/site-settings-review' into feature/3441-site-se…
tonyr59h Dec 7, 2015
bcac6d8
Adding dividers and fixing wrapped number picker element values
tonyr59h Dec 7, 2015
0cb0b19
Design cleanup, mostly ActionMode changes, some font tweaks, shadowing
tonyr59h Dec 8, 2015
54830dd
Adding analytics
tonyr59h Dec 8, 2015
367389f
Showing keyboard on input dialogs, fixing delete bug, editing design
tonyr59h Dec 9, 2015
93b7e77
Fixing subscreen header fonts
tonyr59h Dec 9, 2015
9383f4f
Updating analytics based on feedback from PR
tonyr59h Dec 9, 2015
857d8ee
Cleaning up the code, re-using dialog creation work
tonyr59h Dec 9, 2015
9d3c246
Changing number picker dialog font colors when toggling switch
tonyr59h Dec 10, 2015
3544f15
Formatting number picker display strings
tonyr59h Dec 10, 2015
bcee50e
Version checking self-hosted responses to determine if settings are s…
tonyr59h Dec 10, 2015
4b9a7e0
Fixing crash from 0 length substring
tonyr59h Dec 10, 2015
678ce08
Verifying fragment is active before updating views
tonyr59h Dec 10, 2015
86518ab
Adding values of updated settings to analytics
tonyr59h Dec 10, 2015
1fe87b5
Fixing crash when deleting multiple items from list editor
tonyr59h Dec 10, 2015
c25ac5d
Showing keyboard for input in list editor when FAB is clicked
tonyr59h Dec 11, 2015
8a73b8e
Adding more levels to Threading picker, fixing fonts and a crash
tonyr59h Dec 11, 2015
f9ff589
Adjusting font for Discussion toolbar
tonyr59h Dec 11, 2015
84b9e5f
Checking for valid length string before serializing
tonyr59h Dec 11, 2015
a5e369f
Savings settings as soon as they change per discussion with Matt
tonyr59h Dec 11, 2015
b6cf058
Lots of code cleanup
tonyr59h Dec 12, 2015
d3682b4
Creating constants/resources for strings
tonyr59h Dec 14, 2015
ecaf8f9
Fixing switch implementation for paging and close after settings
tonyr59h Dec 14, 2015
319437a
Merge branch 'feature/site-settings-review' into feature/3441-site-se…
tonyr59h Dec 14, 2015
334f335
Renaming language selection stat
tonyr59h Dec 14, 2015
f9a0eec
Saving related post changes remotely
tonyr59h Dec 14, 2015
8de264e
Hiding Settings option if user does not have permission to edit them
tonyr59h Dec 14, 2015
475a5d5
Fixing self-hosted settings deserialization and password display
tonyr59h Dec 15, 2015
6641545
Fixing issues with saving close after and paging settings
tonyr59h Dec 15, 2015
866afb5
Saving Blacklist and Hold for Moderation lists when dismissing dialog
tonyr59h Dec 15, 2015
91ff1dd
Fixing some broken discussion settings serialization
tonyr59h Dec 15, 2015
0b5b59a
Ensuring non-null formats list when calling getFormats()
tonyr59h Dec 16, 2015
6b25f98
Strings cleanup
tonyr59h Dec 16, 2015
9e8496b
Using correct key when serializing hold for moderation list changes
tonyr59h Dec 16, 2015
9eef65d
Saving hold for moderation and blacklist changes immediately
tonyr59h Dec 16, 2015
96df18b
Setting list divider programmatically
tonyr59h Dec 16, 2015
5592667
Removing preferences when user does not have admin privileges
tonyr59h Dec 16, 2015
29f2a1d
Delaying fetching settings to allow new screen to load immediately
tonyr59h Dec 17, 2015
46eb536
Not showing DetailListPreferences if there is no list
tonyr59h Dec 17, 2015
1ba9a8b
Fixing fetching boolean logic
tonyr59h Dec 17, 2015
2d792a2
Including certain preference toggle values in the database + code clean
tonyr59h Jan 5, 2016
49661eb
Capitalizing first letter of language summary string
tonyr59h Jan 5, 2016
e43b88c
Default Format value set to standard if value is not in format map
tonyr59h Jan 5, 2016
fbc4165
Moving Uncategorized to the beginning of the category list
tonyr59h Jan 5, 2016
c01ba16
Fixing implementation of Threading, Paging, and Close after preferences
tonyr59h Jan 5, 2016
d398c6e
Fixing wrapped number picker values
tonyr59h Jan 5, 2016
9e462ec
Self-hosted sites will use the old settings for now
tonyr59h Jan 5, 2016
7fbe1dd
Adjusting positions of number picker elements
tonyr59h Jan 6, 2016
44293ae
Merge pull request #3562 from wordpress-mobile/feature/3441-only-dotcom
kwonye Jan 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/**
* Holds blog settings and provides methods to (de)serialize .com and self-hosted network calls.
*/

public class SiteSettingsModel {
public static final int RELATED_POSTS_ENABLED_FLAG = 0x1;
public static final int RELATED_POST_HEADER_FLAG = 0x2;
Expand All @@ -37,9 +38,12 @@ public class SiteSettingsModel {
public static final String ALLOW_COMMENTS_COLUMN_NAME = "allowComments";
public static final String SEND_PINGBACKS_COLUMN_NAME = "sendPingbacks";
public static final String RECEIVE_PINGBACKS_COLUMN_NAME = "receivePingbacks";
public static final String SHOULD_CLOSE_AFTER_COLUMN_NAME = "shouldCloseAfter";
public static final String CLOSE_AFTER_COLUMN_NAME = "closeAfter";
public static final String SORT_BY_COLUMN_NAME = "sortBy";
public static final String SHOULD_THREAD_COLUMN_NAME = "shouldThread";
public static final String THREADING_COLUMN_NAME = "threading";
public static final String SHOULD_PAGE_COLUMN_NAME = "shouldPage";
public static final String PAGING_COLUMN_NAME = "paging";
public static final String MANUAL_APPROVAL_COLUMN_NAME = "manualApproval";
public static final String IDENTITY_REQUIRED_COLUMN_NAME = "identityRequired";
Expand Down Expand Up @@ -71,9 +75,12 @@ public class SiteSettingsModel {
ALLOW_COMMENTS_COLUMN_NAME + " BOOLEAN, " +
SEND_PINGBACKS_COLUMN_NAME + " BOOLEAN, " +
RECEIVE_PINGBACKS_COLUMN_NAME + " BOOLEAN, " +
SHOULD_CLOSE_AFTER_COLUMN_NAME + " BOOLEAN, " +
CLOSE_AFTER_COLUMN_NAME + " INTEGER, " +
SORT_BY_COLUMN_NAME + " INTEGER, " +
SHOULD_THREAD_COLUMN_NAME + " BOOLEAN, " +
THREADING_COLUMN_NAME + " INTEGER, " +
SHOULD_PAGE_COLUMN_NAME + " BOOLEAN, " +
PAGING_COLUMN_NAME + " INTEGER, " +
MANUAL_APPROVAL_COLUMN_NAME + " BOOLEAN, " +
IDENTITY_REQUIRED_COLUMN_NAME + " BOOLEAN, " +
Expand Down Expand Up @@ -106,9 +113,12 @@ public class SiteSettingsModel {
public boolean allowComments;
public boolean sendPingbacks;
public boolean receivePingbacks;
public boolean shouldCloseAfter;
public int closeCommentAfter;
public int sortCommentsBy;
public boolean shouldThreadComments;
public int threadingLevels;
public boolean shouldPageComments;
public int commentsPerPage;
public boolean commentApprovalRequired;
public boolean commentsRequireIdentity;
Expand Down Expand Up @@ -181,9 +191,12 @@ public void copyFrom(SiteSettingsModel other) {
allowComments = other.allowComments;
sendPingbacks = other.sendPingbacks;
receivePingbacks = other.receivePingbacks;
shouldCloseAfter = other.shouldCloseAfter;
closeCommentAfter = other.closeCommentAfter;
sortCommentsBy = other.sortCommentsBy;
shouldThreadComments = other.shouldThreadComments;
threadingLevels = other.threadingLevels;
shouldPageComments = other.shouldPageComments;
commentsPerPage = other.commentsPerPage;
commentApprovalRequired = other.commentApprovalRequired;
commentsRequireIdentity = other.commentsRequireIdentity;
Expand Down Expand Up @@ -215,9 +228,12 @@ public void deserializeOptionsDatabaseCursor(Cursor cursor, Map<Integer, Categor
allowComments = getBooleanFromCursor(cursor, ALLOW_COMMENTS_COLUMN_NAME);
sendPingbacks = getBooleanFromCursor(cursor, SEND_PINGBACKS_COLUMN_NAME);
receivePingbacks = getBooleanFromCursor(cursor, RECEIVE_PINGBACKS_COLUMN_NAME);
shouldCloseAfter = getBooleanFromCursor(cursor, SHOULD_CLOSE_AFTER_COLUMN_NAME);
closeCommentAfter = getIntFromCursor(cursor, CLOSE_AFTER_COLUMN_NAME);
sortCommentsBy = getIntFromCursor(cursor, SORT_BY_COLUMN_NAME);
shouldThreadComments = getBooleanFromCursor(cursor, SHOULD_THREAD_COLUMN_NAME);
threadingLevels = getIntFromCursor(cursor, THREADING_COLUMN_NAME);
shouldPageComments = getBooleanFromCursor(cursor, SHOULD_PAGE_COLUMN_NAME);
commentsPerPage = getIntFromCursor(cursor, PAGING_COLUMN_NAME);
commentApprovalRequired = getBooleanFromCursor(cursor, MANUAL_APPROVAL_COLUMN_NAME);
commentsRequireIdentity = getBooleanFromCursor(cursor, IDENTITY_REQUIRED_COLUMN_NAME);
Expand Down Expand Up @@ -283,9 +299,12 @@ public ContentValues serializeToDatabase() {
values.put(ALLOW_COMMENTS_COLUMN_NAME, allowComments);
values.put(SEND_PINGBACKS_COLUMN_NAME, sendPingbacks);
values.put(RECEIVE_PINGBACKS_COLUMN_NAME, receivePingbacks);
values.put(SHOULD_CLOSE_AFTER_COLUMN_NAME, shouldCloseAfter);
values.put(CLOSE_AFTER_COLUMN_NAME, closeCommentAfter);
values.put(SORT_BY_COLUMN_NAME, sortCommentsBy);
values.put(SHOULD_THREAD_COLUMN_NAME, shouldThreadComments);
values.put(THREADING_COLUMN_NAME, threadingLevels);
values.put(SHOULD_PAGE_COLUMN_NAME, shouldPageComments);
values.put(PAGING_COLUMN_NAME, commentsPerPage);
values.put(MANUAL_APPROVAL_COLUMN_NAME, commentApprovalRequired);
values.put(IDENTITY_REQUIRED_COLUMN_NAME, commentsRequireIdentity);
Expand Down
257 changes: 235 additions & 22 deletions WordPress/src/main/java/org/wordpress/android/ui/WPNumberPicker.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,262 @@
package org.wordpress.android.ui;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.TextView;

import org.wordpress.android.R;
import org.wordpress.android.widgets.TypefaceCache;
import org.wordpress.android.util.WPPrefUtils;

import java.lang.reflect.Field;

public class WPNumberPicker extends NumberPicker {
private static final String DIVIDER_FIELD = "mSelectionDivider";
private static final String INPUT_FIELD = "mInputText";
private static final String INDICES_FIELD = "mSelectorIndices";
private static final String CUR_OFFSET_FIELD = "mCurrentScrollOffset";
private static final String SELECTOR_HEIGHT_FIELD = "mSelectorElementHeight";
private static final String INITIAL_OFFSET_FIELD = "mInitialScrollOffset";
private static final String CURRENT_OFFSET_FIELD = "mCurrentScrollOffset";
private static final String PAINT_FIELD = "mSelectorWheelPaint";

private static final int DISPLAY_COUNT = 5;
private static final int MIDDLE_INDEX = 2;

private Field mOffsetField;
private Field mSelectorHeight;
private Field mSelectorIndices;
private Field mInitialOffset;
private Field mCurrentOffset;

private EditText mInputView;
private Formatter mFormatter;
private Paint mPaint;
private int[] mDisplayValues;

public WPNumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
setWrapSelectorWheel(false);
mDisplayValues = new int[DISPLAY_COUNT];
getFieldsViaReflection();
}

@Override
public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
super.addView(child, index, params);
if (child instanceof TextView) {
WPPrefUtils.layoutAsNumberPickerPeek((TextView) child);
}
}

@Override
public void addView(View child) {
super.addView(child);
updateView(child);
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
updateIntitialOffset();
setVerticalFadingEdgeEnabled(false);
setHorizontalFadingEdgeEnabled(false);
mInputView.setVisibility(View.INVISIBLE);
}

@Override
public void addView(View child, int index,
android.view.ViewGroup.LayoutParams params) {
super.addView(child, index, params);
updateView(child);
public void setValue(int value) {
if (value < getMinValue()) value = getMinValue();
if (value > getMaxValue()) value = getMaxValue();
super.setValue(value);
EditText view = (EditText) getChildAt(0);
WPPrefUtils.layoutAsNumberPickerSelected(view);
}

@Override
public void addView(View child, android.view.ViewGroup.LayoutParams params) {
super.addView(child, params);
updateView(child);
protected void onDraw(Canvas canvas) {
int[] selectorIndices = getIndices();
setIndices(new int[0]);
setIndices(selectorIndices);

// Draw the middle number with a different font
setDisplayValues();
float elementHeight = getSelectorElementHeight();
float x = ((getRight() - getLeft()) / 2.0f);
float y = getScrollOffset();
Paint paint = mInputView.getPaint();
paint.setTextAlign(Paint.Align.CENTER);
//noinspection deprecation
paint.setColor(getResources().getColor(R.color.blue_medium));
int alpha = isEnabled() ? 255 : 96;
paint.setAlpha(alpha);
mPaint.setAlpha(alpha);

int offset = getResources().getDimensionPixelSize(R.dimen.margin_medium);
// Draw the visible values
for (int i = 0; i < DISPLAY_COUNT; ++i) {
String scrollSelectorValue;
if (mFormatter != null) {
scrollSelectorValue = mFormatter.format(mDisplayValues[i]);
} else {
scrollSelectorValue = String.valueOf(mDisplayValues[i]);
}
if (i == MIDDLE_INDEX) {
canvas.drawText(scrollSelectorValue, x, y - ((paint.descent() + paint.ascent()) / 2) - offset, paint);
} else {
canvas.drawText(scrollSelectorValue, x, y - ((mPaint.descent() + mPaint.ascent()) / 2) - offset, mPaint);
}
y += elementHeight;
}
}

@Override
public void setFormatter(Formatter formatter) {
super.setFormatter(formatter);
mFormatter = formatter;
}

private void setDisplayValues() {
int value = getValue();
for (int i = 0; i < DISPLAY_COUNT; ++i) {
mDisplayValues[i] = value - MIDDLE_INDEX + i;
if (mDisplayValues[i] < getMinValue()) {
mDisplayValues[i] = getMaxValue() + (mDisplayValues[i] + 1 - getMinValue());
} else if (mDisplayValues[i] > getMaxValue()) {
mDisplayValues[i] = getMinValue() + (mDisplayValues[i] - getMaxValue() - 1);
}
}
}

private void setIndices(int[] indices) {
if (mSelectorIndices != null) {
try {
mSelectorIndices.set(this, indices);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

private int[] getIndices() {
if (mSelectorIndices != null) {
try {
return (int[]) mSelectorIndices.get(this);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}

return null;
}

private void updateView(View view) {
if (view instanceof TextView) {
Typeface type = TypefaceCache.getTypeface(getContext(),
TypefaceCache.FAMILY_OPEN_SANS,
Typeface.NORMAL,
TypefaceCache.VARIATION_NORMAL);
((TextView) view).setTypeface(type);
((TextView) view).setTextSize(24);
((TextView) view).setTextColor(getResources().getColor(R.color.wp_blue));
private int getScrollOffset() {
if (mOffsetField != null) {
try {
return (Integer) mOffsetField.get(this);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}

return 0;
}

private int getSelectorElementHeight() {
if (mSelectorHeight != null) {
try {
return (Integer) mSelectorHeight.get(this);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}

return 0;
}

private void updateIntitialOffset() {
if (mInitialOffset != null) {
try {
int offset = (Integer) mInitialOffset.get(this) - getSelectorElementHeight();
mInitialOffset.set(this, offset);
// Only do this once
mInitialOffset = null;

if (mCurrentOffset != null) {
mCurrentOffset.set(this, offset);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}

/**
* From https://www.snip2code.com/Snippet/67740/NumberPicker-with-transparent-selection-
*/
private void removeDividers(Class<?> clazz) {
Field selectionDivider = getFieldAndSetAccessible(clazz, DIVIDER_FIELD);
if (selectionDivider != null) {
try {
selectionDivider.set(this, null);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

private void getTextPaint(Class<?> clazz) {
Field paint = getFieldAndSetAccessible(clazz, PAINT_FIELD);
if (paint != null) {
try {
mPaint = (Paint) paint.get(this);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

private void getInputField(Class<?> clazz) {
Field inputField = getFieldAndSetAccessible(clazz, INPUT_FIELD);
if (inputField != null) {
try {
mInputView = ((EditText) inputField.get(this));
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

/**
* Gets a class field using reflection and makes it accessible.
*/
private Field getFieldAndSetAccessible(Class<?> clazz, String fieldName) {
Field field = null;
try {
field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}

return field;
}

private void getFieldsViaReflection() {
Class<?> numberPickerClass = null;
try {
numberPickerClass = Class.forName(NumberPicker.class.getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (numberPickerClass == null) return;

mSelectorHeight = getFieldAndSetAccessible(numberPickerClass, SELECTOR_HEIGHT_FIELD);
mOffsetField = getFieldAndSetAccessible(numberPickerClass, CUR_OFFSET_FIELD);
mSelectorIndices = getFieldAndSetAccessible(numberPickerClass, INDICES_FIELD);
mInitialOffset = getFieldAndSetAccessible(numberPickerClass, INITIAL_OFFSET_FIELD);
mCurrentOffset = getFieldAndSetAccessible(numberPickerClass, CURRENT_OFFSET_FIELD);

getTextPaint(numberPickerClass);
getInputField(numberPickerClass);
removeDividers(numberPickerClass);
setIndices(new int[DISPLAY_COUNT]);
}
}
Loading