Skip to content

Commit

Permalink
Version 1.1.1
Browse files Browse the repository at this point in the history
- Fix up reply editor behavior
- Make Inbox page properly navigate to page provided by NAV_PAGE extra
- Fix bugs
  • Loading branch information
TheKeeperOfPie committed Jul 27, 2015
1 parent d095878 commit 8919b33
Show file tree
Hide file tree
Showing 30 changed files with 940 additions and 454 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId "com.winsonchiu.reader"
minSdkVersion 17
targetSdkVersion 22
versionCode 40
versionName "1.1"
versionCode 43
versionName "1.1.1"
}
buildTypes {
release {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application
android:name=".CustomApplication"
Expand Down Expand Up @@ -53,6 +54,7 @@
android:exported="false" >
<intent-filter>
<action android:name="com.winsonchiu.reader.inbox.Receiver.INTENT_INBOX" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

Expand Down
401 changes: 339 additions & 62 deletions app/src/main/java/com/winsonchiu/reader/FragmentNewMessage.java

Large diffs are not rendered by default.

96 changes: 66 additions & 30 deletions app/src/main/java/com/winsonchiu/reader/FragmentNewPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.animation.Animator;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
Expand All @@ -28,6 +29,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.webkit.URLUtil;
import android.widget.EditText;
import android.widget.ImageButton;
Expand Down Expand Up @@ -59,14 +61,14 @@ public class FragmentNewPost extends FragmentBase implements Toolbar.OnMenuItemC
public static final String IS_EDIT = "isEdit";
public static final String EDIT_ID = "editId";
public static final String TAG = FragmentNewPost.class.getCanonicalName();
private static final int PAGE_BODY = 0;
private static final int PAGE_POST = 0;
private static final int PAGE_PREVIEW = 1;

private CoordinatorLayout layoutCoordinator;
private AppBarLayout layoutAppBar;
private Toolbar toolbar;
private TextView textInfo;
private TextView textSubmit;
private CoordinatorLayout layoutCoordinator;
private AppBarLayout layoutAppBar;
private NestedScrollView scrollText;
private EditText editTextTitle;
private EditText editTextBody;
Expand Down Expand Up @@ -156,6 +158,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editTextBody.getWindowToken(), 0);
mListener.onNavigationBackClick();
}
});
Expand All @@ -182,15 +187,21 @@ public void onClick(View v) {
else {
editTextBody.setHint("Text");
}
editTextBody.setOnFocusChangeListener(new View.OnFocusChangeListener() {

View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar
.getLayoutParams()).getBehavior();
behaviorAppBar
.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
}
});
};

editTextTitle.setOnFocusChangeListener(onFocusChangeListener);
editTextBody.setOnFocusChangeListener(onFocusChangeListener);

editMarginDefault = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
editMarginWithActions = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56,
Expand All @@ -200,7 +211,7 @@ public void onFocusChange(View v, boolean hasFocus) {
viewDivider = view.findViewById(R.id.view_divider);

toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
toolbarActions.inflateMenu(R.menu.menu_reply_actions);
toolbarActions.inflateMenu(R.menu.menu_editor_actions);
toolbarActions.setOnMenuItemClickListener(this);

tabLayout = (TabLayout) view.findViewById(R.id.layout_tab);
Expand All @@ -214,8 +225,8 @@ public void onFocusChange(View v, boolean hasFocus) {
public CharSequence getPageTitle(int position) {

switch (position) {
case PAGE_BODY:
return getString(R.string.page_reply);
case PAGE_POST:
return getString(R.string.page_post);
case PAGE_PREVIEW:
return getString(R.string.page_preview);
}
Expand Down Expand Up @@ -256,7 +267,7 @@ public void onPageScrolled(int position,
float positionOffset,
int positionOffsetPixels) {

if (position == PAGE_BODY && toolbarActions.getVisibility() == View.VISIBLE) {
if (position == PAGE_POST && toolbarActions.getVisibility() == View.VISIBLE) {
float translationY = positionOffset * (toolbarActions.getHeight() + viewDivider
.getHeight());
viewDivider.setTranslationY(translationY);
Expand All @@ -277,7 +288,7 @@ public void onPageSelected(int position) {
}
}
if (Reddit.POST_TYPE_SELF.equals(postType)) {
itemHideActions.setVisible(position == PAGE_BODY);
itemHideActions.setVisible(position == PAGE_POST);
}
}

Expand Down Expand Up @@ -322,7 +333,6 @@ public void onErrorResponse(VolleyError error) {
}, 0);
}


view.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
Expand All @@ -349,6 +359,7 @@ public void onGlobalLayout() {
}
}

// Toggle visibility to fix weird bug causing tabs to not be added
tabLayout.setVisibility(View.GONE);
tabLayout.setVisibility(View.VISIBLE);
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Expand All @@ -359,7 +370,7 @@ public void onGlobalLayout() {
}

private void setUpOptionsMenu() {
toolbar.inflateMenu(R.menu.menu_reply);
toolbar.inflateMenu(R.menu.menu_new_post);
toolbar.setOnMenuItemClickListener(this);
menu = toolbar.getMenu();
itemHideActions = menu.findItem(R.id.item_hide_actions);
Expand Down Expand Up @@ -438,6 +449,9 @@ private void submitEdit() {
@Override
public void onResponse(String response) {

InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editTextBody.getWindowToken(), 0);
mListener.getControllerLinks().reloadAllLinks(false);
mListener.onNavigationBackClick();
}
Expand Down Expand Up @@ -522,6 +536,9 @@ public void onResponse(String response) {
e.printStackTrace();
}

InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editTextBody.getWindowToken(), 0);
mListener.getControllerLinks().reloadAllLinks(false);
mListener.onNavigationBackClick();

Expand All @@ -539,9 +556,10 @@ public void onErrorResponse(VolleyError error) {
public boolean onMenuItemClick(MenuItem item) {

int selectionStart = editTextBody.getSelectionStart();
boolean isNewLine = editTextBody.getText().length() == 0 || editTextBody.getText().charAt(editTextBody.length() - 1) == '\n';

switch (item.getItemId()) {
case R.id.item_send_reply:
case R.id.item_submit_post:
if (getArguments().getBoolean(IS_EDIT, false)) {
submitEdit();
}
Expand All @@ -552,37 +570,55 @@ public boolean onMenuItemClick(MenuItem item) {
case R.id.item_hide_actions:
toggleActions();
break;
case R.id.item_reply_italicize:
case R.id.item_editor_italicize:
editTextBody.getText().insert(selectionStart, "**");
editTextBody.setSelection(selectionStart + 1);
break;
case R.id.item_reply_bold:
case R.id.item_editor_bold:
editTextBody.getText().insert(selectionStart, "****");
editTextBody.setSelection(selectionStart + 2);
break;
case R.id.item_reply_strikethrough:
case R.id.item_editor_strikethrough:
editTextBody.getText().insert(selectionStart, "~~~~");
editTextBody.setSelection(selectionStart + 2);
break;
case R.id.item_reply_quote:
editTextBody.getText().insert(selectionStart, "\n> ");
editTextBody.setSelection(selectionStart + 2);
case R.id.item_editor_quote:
if (isNewLine) {
editTextBody.getText().insert(selectionStart, "> ");
editTextBody.setSelection(selectionStart + 2);
}
else {
editTextBody.getText().insert(selectionStart, "\n> ");
editTextBody.setSelection(selectionStart + 3);
}
break;
case R.id.item_reply_link:
String labelText = getString(R.string.reply_label_text);
String labelLink = getString(R.string.reply_label_link);
case R.id.item_editor_link:
String labelText = getString(R.string.editor_label_text);
String labelLink = getString(R.string.editor_label_link);
int indexStart = selectionStart + 1;
int indexEnd = indexStart + labelText.length();
editTextBody.getText().insert(selectionStart, "[" + labelText + "](" + labelLink + ")");
editTextBody.setSelection(indexStart, indexEnd);
break;
case R.id.item_reply_list_bulleted:
editTextBody.getText().insert(selectionStart, "\n\n* \n* \n* ");
editTextBody.setSelection(selectionStart + 4);
case R.id.item_editor_list_bulleted:
if (isNewLine) {
editTextBody.getText().insert(selectionStart, "* \n* \n* ");
editTextBody.setSelection(selectionStart + 2);
}
else {
editTextBody.getText().insert(selectionStart, "\n\n* \n* \n* ");
editTextBody.setSelection(selectionStart + 4);
}
break;
case R.id.item_reply_list_numbered:
editTextBody.getText().insert(selectionStart, "\n\n1. \n2. \n3. ");
editTextBody.setSelection(selectionStart + 5);
case R.id.item_editor_list_numbered:
if (isNewLine) {
editTextBody.getText().insert(selectionStart, "1. \n2. \n3. ");
editTextBody.setSelection(selectionStart + 3);
}
else {
editTextBody.getText().insert(selectionStart, "\n\n1. \n2. \n3. ");
editTextBody.setSelection(selectionStart + 5);
}
break;
}

Expand Down
52 changes: 35 additions & 17 deletions app/src/main/java/com/winsonchiu/reader/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.winsonchiu.reader.comments.ControllerComments;
import com.winsonchiu.reader.comments.FragmentComments;
import com.winsonchiu.reader.comments.FragmentReply;
import com.winsonchiu.reader.data.Page;
import com.winsonchiu.reader.data.reddit.Comment;
import com.winsonchiu.reader.data.reddit.Link;
import com.winsonchiu.reader.data.reddit.Message;
Expand Down Expand Up @@ -166,7 +167,7 @@ public void onDrawerOpened(View drawerView) {
public void onDrawerClosed(View drawerView) {
invalidateOptionsMenu();
if (loadId != 0) {
selectNavigationItem(loadId, 0, true);
selectNavigationItem(loadId, null, true);
}
}

Expand All @@ -190,12 +191,14 @@ public void onDrawerStateChanged(int newState) {
else {
Log.d(TAG, "Not valid URL: " + urlString);
getControllerLinks().loadFrontPage(Sort.HOT, true);
selectNavigationItem(getIntent().getIntExtra(NAV_ID, R.id.item_home), getIntent().getIntExtra(NAV_PAGE, 0), false);
selectNavigationItem(getIntent().getIntExtra(NAV_ID, R.id.item_home), getIntent().getStringExtra(
NAV_PAGE), false);
}
}
else {
getControllerLinks().loadFrontPage(Sort.HOT, true);
selectNavigationItem(getIntent().getIntExtra(NAV_ID, R.id.item_home), getIntent().getIntExtra(NAV_PAGE, 0), false);
selectNavigationItem(getIntent().getIntExtra(NAV_ID, R.id.item_home), getIntent().getStringExtra(
NAV_PAGE), false);
}
}

Expand All @@ -222,7 +225,15 @@ public void onResponse(String response) {
.getJSONObject("data")
.getJSONArray("things")
.getJSONObject(0), 0);
getControllerComments().insertComment(newComment);
if (getFragmentManager().findFragmentByTag(FragmentComments.TAG) != null) {
getControllerComments().insertComment(newComment);
}
if (getFragmentManager().findFragmentByTag(FragmentProfile.TAG) != null) {
getControllerProfile().insertComment(newComment);
}
if (getFragmentManager().findFragmentByTag(FragmentInbox.TAG) != null) {
getControllerInbox().insertComment(newComment);
}
}
catch (JSONException e) {
e.printStackTrace();
Expand Down Expand Up @@ -686,7 +697,7 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {

}

private void selectNavigationItem(final int id, int page, boolean animate) {
private void selectNavigationItem(final int id, String page, boolean animate) {

loadId = 0;

Expand Down Expand Up @@ -743,22 +754,29 @@ private void selectNavigationItem(final int id, int page, boolean animate) {

break;
case R.id.item_inbox:
switch (page) {
case ControllerInbox.PAGE_INBOX:
getControllerInbox().setPage("Inbox");
break;
case ControllerInbox.PAGE_UNREAD:
getControllerInbox().setPage("Unread");
break;
case ControllerInbox.PAGE_SENT:
getControllerInbox().setPage("Sent");
break;
Log.d(TAG, "Page: " + page);

if (!TextUtils.isEmpty(page)) {
switch (page) {
case ControllerInbox.INBOX:
getControllerInbox()
.setPage(new Page(page, getString(R.string.inbox_page_inbox)));
break;
case ControllerInbox.UNREAD:
getControllerInbox()
.setPage(new Page(page, getString(R.string.inbox_page_unread)));
break;
case ControllerInbox.SENT:
getControllerInbox()
.setPage(new Page(page, getString(R.string.inbox_page_sent)));
break;
}
}

getControllerInbox().reload();
fragmentTransaction.replace(R.id.frame_fragment,
FragmentInbox.newInstance(),
FragmentInbox.TAG);
FragmentInbox.newInstance(),
FragmentInbox.TAG);
break;
}

Expand Down
Loading

0 comments on commit 8919b33

Please sign in to comment.