Skip to content

Commit

Permalink
add new preference option: character count instead word count on note…
Browse files Browse the repository at this point in the history
… info (#550)

* add option: character count instead word count on note info(InfoBottomSheetDialog)

* update to show both char and word count, not optional.

* cleanup for char count func.

* cleanup for char count func.

* update layout for characters count

* spacing and code formatting

* word count message format

* word count message format
  • Loading branch information
lenchan139 authored and roundhill committed Jul 25, 2018
1 parent 738a2e7 commit 9b4523b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 46 deletions.
10 changes: 2 additions & 8 deletions Simplenote/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,19 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'recyclerview-v7'
}

// Automattic and WordPress dependencies
compile "com.simperium.android:simperium:0.6.9"
compile 'com.simperium.android:simperium:0.6.9'
compile 'com.automattic:tracks:1.1.0'
compile 'org.wordpress:passcodelock:1.5.1'

// Google Support
compile "com.android.support:appcompat-v7:$googleVersion"
compile "com.android.support:design:$googleVersion"
compile "com.android.support:support-vector-drawable:$googleVersion"
compile "com.android.support:preference-v7:$googleVersion"
compile "com.android.support:preference-v14:$googleVersion"

// Google Play Services
compile "com.google.android.gms:play-services-analytics:$playServiceVersion"
compile "com.google.android.gms:play-services-wearable:$playServiceVersion"

// Third Party
compile 'com.takisoft.fix:preference-v7:24.2.1.0'
compile 'com.loopj.android:android-async-http:1.4.9'
Expand All @@ -61,9 +57,7 @@ dependencies {
compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true;
}

implementation "com.android.support:customtabs:$googleVersion"

wearApp project(':Wear')
}

Expand All @@ -75,7 +69,7 @@ android {
}

compileSdkVersion 26
buildToolsVersion "26.0.2"
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "com.automattic.simplenote"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class InfoBottomSheetDialog extends BottomSheetDialogBase {
private SwitchCompat mInfoMarkdownSwitch;
private ImageButton mCopyButton;
private ImageButton mShareButton;

private Fragment mFragment;

public InfoBottomSheetDialog(@NonNull Fragment fragment, @NonNull final InfoSheetListener infoSheetListener) {
Expand All @@ -41,7 +40,6 @@ public InfoBottomSheetDialog(@NonNull Fragment fragment, @NonNull final InfoShee
mFragment = fragment;

View infoView = LayoutInflater.from(fragment.getActivity()).inflate(R.layout.bottom_sheet_info, null, false);

mInfoModifiedDate = (TextView) infoView.findViewById(R.id.info_modified_date_text);
mInfoWords = (TextView) infoView.findViewById(R.id.info_words_text);
mInfoLinkUrl = (TextView) infoView.findViewById(R.id.info_public_link_url);
Expand Down Expand Up @@ -102,10 +100,9 @@ public void show(Note note) {
if (mFragment.isAdded()) {
String date = DateTimeUtils.getDateText(mFragment.getActivity(), note.getModificationDate());
mInfoModifiedDate.setText(String.format(mFragment.getString(R.string.modified_time), date));
mInfoWords.setText(getWordCount(note.getContent()));
mInfoPinSwitch.setChecked(note.isPinned());
mInfoMarkdownSwitch.setChecked(note.isMarkdownEnabled());

mInfoWords.setText(getCombinedCount(note.getContent()));
if (note.isPublished()) {
mInfoLinkTitle.setText(mFragment.getString(R.string.public_link));
mInfoLinkUrl.setText(note.getPublishedUrl());
Expand All @@ -124,9 +121,11 @@ public void show(Note note) {
}
}

private String getWordCount(String content) {
private String getCombinedCount(String content) {
return String.format("%s\n%s", getWordCount(content), getCharactersCount(content));
}

if (TextUtils.isEmpty(content)) return "";
private String getWordCount(String content) {

int numWords = (content.trim().length() == 0) ? 0 : content.trim().split("([\\W]+)").length;

Expand All @@ -136,6 +135,12 @@ private String getWordCount(String content) {
return String.format("%s %s", formattedWordCount, wordCountString);
}

private String getCharactersCount(String content) {
int numChars = content.length();
String charCount = NumberFormat.getInstance().format(numChars);
String charCountString = mFragment.getResources().getQuantityString(R.plurals.char_count, numChars);
return String.format("%s %s", charCount, charCountString);
}
public interface InfoSheetListener {
void onInfoPinSwitchChanged(boolean isSwitchedOn);

Expand Down
67 changes: 35 additions & 32 deletions Simplenote/src/main/res/layout/bottom_sheet_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,48 @@
android:layout_height="match_parent"
app:theme="@style/Theme.Simplestyle">

<com.automattic.simplenote.widgets.RobotoRegularTextView
android:id="@+id/info_modified_date_text"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/linearDateWordCountInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:paddingBottom="@dimen/padding_extra_large"
android:paddingEnd="@dimen/padding_large"
android:paddingLeft="@dimen/padding_large"
android:paddingRight="@dimen/padding_large"
android:paddingStart="@dimen/padding_large"
android:paddingTop="@dimen/padding_extra_large"
android:textColor="@color/grey"
tools:text="Modified Jan 1, 20015, 8:00AM"
/>
android:orientation="horizontal">

<com.automattic.simplenote.widgets.RobotoRegularTextView
android:id="@+id/info_words_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingBottom="@dimen/padding_extra_large"
android:paddingEnd="@dimen/padding_large"
android:paddingLeft="@dimen/padding_large"
android:paddingRight="@dimen/padding_large"
android:paddingStart="@dimen/padding_large"
android:paddingTop="@dimen/padding_extra_large"
android:textColor="@color/grey"
tools:text="101 words"
/>
<com.automattic.simplenote.widgets.RobotoRegularTextView
android:id="@+id/info_modified_date_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingBottom="@dimen/padding_extra_large"
android:paddingEnd="@dimen/padding_large"
android:paddingLeft="@dimen/padding_large"
android:paddingRight="@dimen/padding_large"
android:paddingStart="@dimen/padding_large"
android:paddingTop="@dimen/padding_extra_large"
android:textColor="@color/grey"
tools:text="Modified Jan 1, 20015, 8:00AM" />

<com.automattic.simplenote.widgets.RobotoRegularTextView
android:id="@+id/info_words_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:gravity="end"
android:paddingBottom="@dimen/padding_extra_large"
android:paddingEnd="@dimen/padding_large"
android:paddingLeft="@dimen/padding_large"
android:paddingRight="@dimen/padding_large"
android:paddingStart="@dimen/padding_large"
android:paddingTop="@dimen/padding_extra_large"
android:textColor="@color/grey"
tools:text="101 words\n1010 characters" />
</LinearLayout>
<View
android:id="@+id/info_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/info_words_text"
android:layout_below="@id/linearDateWordCountInfo"
android:background="@color/divider_grey"/>

<android.support.v7.widget.SwitchCompat
Expand Down
4 changes: 4 additions & 0 deletions Simplenote/src/main/res/values/plurals.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<item quantity="one">@string/word</item>
<item quantity="other">@string/words</item>
</plurals>
<plurals name="char_count">
<item quantity="one">@string/character</item>
<item quantity="other">@string/characters</item>
</plurals>
</resources>
3 changes: 3 additions & 0 deletions Simplenote/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<string name="markdown">Markdown</string>
<string name="markdown_hide">Hide Markdown</string>
<string name="markdown_show">Show Markdown</string>
<string name="character">Character</string>
<string name="characters">Characters</string>

<!-- Preferences -->
<string name="general">General</string>
Expand Down Expand Up @@ -201,4 +203,5 @@
<string name="error_history">Couldn\'t retrieve history.</string>
<string name="or">or</string>
<string name="sign_in_with_wordpress_com">Sign in with WordPress.com</string>

</resources>
2 changes: 2 additions & 0 deletions Simplenote/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
android:key="pref_key_theme"
android:summary="%s"
android:title="@string/theme"/>


</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 9b4523b

Please sign in to comment.