Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 23 additions & 9 deletions res/layout/notifications_big_badge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,48 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
android:orientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center" >
android:layout_gravity="center"
android:orientation="vertical">

<com.android.volley.toolbox.NetworkImageView
android:id="@+id/badge"
android:layout_width="170dp"
android:layout_height="170dp"
android:minWidth="170dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
android:minHeight="170dp"
android:scaleType="fitCenter"
android:minWidth="170dp"
android:scaleType="fitCenter" />

<TextView
android:id="@+id/text_stats_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp" />
android:drawableLeft="@drawable/note_icon_stats"
android:padding="16dp"
android:text="@string/view_stats_activity"
android:textColor="@color/reader_hyperlink"
android:textSize="@dimen/reader_text_sz_large"
android:background="@drawable/reader_transparent_selector"
android:visibility="gone" />

<TextView
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:textSize="20sp"
android:paddingRight="16dp"
android:textAlignment="center"
android:textIsSelectable="true" />
android:textColorLink="@color/reader_hyperlink"
android:textIsSelectable="true"
android:textSize="20sp" />
</LinearLayout>

</ScrollView>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
<string name="stats_password">Password</string>
<string name="invalid_login">Incorrect Login</string>
<string name="view_stats_full_site">View full site</string>
<string name="view_stats_activity">View stats</string>

<!-- stats: labels for the views -->
<string name="stats_view_visitors_and_views">Visitors and Views</string>
Expand Down
17 changes: 17 additions & 0 deletions src/org/wordpress/android/models/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,23 @@ public Map<String,JSONObject> getActions(){
return mActions;
}

/*
* returns the "meta" section of the note's JSON (not guaranteed to exist)
*/
private JSONObject getJSONMeta() {
return JSONUtil.getJSONChild(this.toJSONObject(), "meta");
}

/*
* returns the value of the passed name in the meta section of the JSON
*/
public int getMetaValueAsInt(String name, int defaultValue) {
JSONObject jsonMeta = getJSONMeta();
if (jsonMeta == null)
return defaultValue;
return jsonMeta.optInt(name, defaultValue);
}

/*
* returns the actions allowed on this note, assumes it's a comment notification
*/
Expand Down
6 changes: 3 additions & 3 deletions src/org/wordpress/android/ui/WPActionBarActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public abstract class WPActionBarActivity extends SherlockFragmentActivity {
protected static final int NOTIFICATIONS_ACTIVITY = 11;

protected static final String LAST_ACTIVITY_PREFERENCE = "wp_pref_last_activity";

protected MenuDrawer mMenuDrawer;
private static int[] blogIDs;
protected boolean isAnimatingRefreshButton;
Expand All @@ -126,7 +126,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4)
mIsXLargeDevice = true;

// configure all the available menu items
mMenuItems.add(new ReaderMenuItem());
mMenuItems.add(new NotificationsMenuItem());
Expand Down Expand Up @@ -194,7 +194,7 @@ protected void createMenuDrawer(int contentViewID) {

mMenuDrawer = attachMenuDrawer();
mMenuDrawer.setContentView(contentViewID);

initMenuDrawer();
}

Expand Down
80 changes: 69 additions & 11 deletions src/org/wordpress/android/ui/notifications/BigBadgeFragment.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package org.wordpress.android.ui.notifications;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;

import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.models.Note;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.util.JSONUtil;

public class BigBadgeFragment extends Fragment implements NotificationFragment {
private Note mNote;
private NetworkImageView mBadgeImageView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle state){
View view = inflater.inflate(R.layout.notifications_big_badge, parent, false);
mBadgeImageView = (NetworkImageView) view.findViewById(R.id.badge);
NetworkImageView badgeImageView = (NetworkImageView) view.findViewById(R.id.badge);

TextView bodyTextView = (TextView) view.findViewById(R.id.body);
bodyTextView.setMovementMethod(LinkMovementMethod.getInstance());
Expand All @@ -37,12 +34,30 @@ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle state
String noteHTML = JSONUtil.queryJSON(getNote().toJSONObject(), "body.html", "");
if (noteHTML.equals(""))
noteHTML = getNote().getSubject();
bodyTextView.setText(Html.fromHtml(noteHTML));
Spanned html = Html.fromHtml(noteHTML);
bodyTextView.setText(html);

// Get the badge
String iconURL = getNote().getIconURL();
if (!iconURL.equals("")) {
mBadgeImageView.setImageUrl(iconURL, WordPress.imageLoader);
if (!iconURL.equals(""))
badgeImageView.setImageUrl(iconURL, WordPress.imageLoader);

// if this is a stats-related note, show stats link and enable tapping badge
// to view stats - but only if the note is for a blog that's visible
if (isStatsNote()) {
final int remoteBlogId = getNote().getMetaValueAsInt("blog_id", -1);
if (WordPress.wpDB.isDotComAccountVisible(remoteBlogId)) {
TextView txtStats = (TextView) view.findViewById(R.id.text_stats_link);
txtStats.setVisibility(View.VISIBLE);
View.OnClickListener statsListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
showStatsActivity(remoteBlogId);
}
};
txtStats.setOnClickListener(statsListener);
badgeImageView.setOnClickListener(statsListener);
}
}
}

Expand All @@ -55,5 +70,48 @@ public void setNote(Note note){
public Note getNote(){
return mNote;
}


/*
* returns true if this is a stats-related notification - currently handles these types:
* followed_milestone_achievement
* post_milestone_achievement
* like_milestone_achievement
* traffic_surge
* best_followed_day_feat
* best_liked_day_feat
* most_liked_day
* most_followed_day
*/
public boolean isStatsNote() {
if (getNote() == null)
return false;

String type = getNote().getType();
if (type == null)
return false;

return (type.contains("_milestone_")
|| type.startsWith("traffic_")
|| type.startsWith("best_")
|| type.startsWith("most_"));
}

/*
* show stats for the passed blog
*/
private void showStatsActivity(int remoteBlogId) {
if (getActivity() == null || isRemoving())
return;

// stats activity is designed to work with the current blog, so switch blogs if necessary
if (WordPress.getCurrentRemoteBlogId() != remoteBlogId) {
// TODO: should we show a toast to let user know blog was switched?
int localBlogId = WordPress.wpDB.getLocalTableBlogIdForRemoteBlogId(remoteBlogId);
WordPress.setCurrentBlog(localBlogId);
}

Intent intent = new Intent(getActivity(), StatsActivity.class);
intent.putExtra(StatsActivity.ARG_NO_MENU_DRAWER, true);
getActivity().startActivity(intent);
}
}
14 changes: 13 additions & 1 deletion src/org/wordpress/android/ui/stats/StatsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class StatsActivity extends WPActionBarActivity {
private static final String SAVED_NAV_POSITION = "SAVED_NAV_POSITION";
private static final String SAVED_WP_LOGIN_STATE = "SAVED_WP_LOGIN_STATE";
private static final int REQUEST_JETPACK = 7000;
public static final String ARG_NO_MENU_DRAWER = "no_menu_drawer";

private Dialog mSignInDialog;
private int mNavPosition = 0;
Expand All @@ -68,6 +69,7 @@ public class StatsActivity extends WPActionBarActivity {
private int mResultCode = -1;
private boolean mIsRestoredFromState = false;
private boolean mIsInFront;
private boolean mNoMenuDrawer = false;

// Used for tablet UI
private static final int TABLET_720DP = 720;
Expand All @@ -86,7 +88,14 @@ public void onCreate(Bundle savedInstanceState) {
return;
}

createMenuDrawer(R.layout.stats_activity);
mNoMenuDrawer = getIntent().getBooleanExtra(ARG_NO_MENU_DRAWER, false);
if (mNoMenuDrawer) {
setContentView(R.layout.stats_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} else {
createMenuDrawer(R.layout.stats_activity);
}

mFragmentContainer = (LinearLayout) findViewById(R.id.stats_fragment_container);
mColumnLeft = (LinearLayout) findViewById(R.id.stats_tablet_col_left);
mColumnRight = (LinearLayout) findViewById(R.id.stats_tablet_col_right);
Expand Down Expand Up @@ -396,6 +405,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
} else if (item.getItemId() == R.id.menu_view_stats_full_site) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://wordpress.com/my-stats")));
return true;
} else if (mNoMenuDrawer && item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/wordpress/android/util/WPRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class WPRestClient {

private static final String NOTIFICATION_FIELDS="id,type,unread,body,subject,timestamp";
private static final String NOTIFICATION_FIELDS="id,type,unread,body,subject,timestamp,meta";
private static final String COMMENT_REPLY_CONTENT_FIELD="content";

private RestClient mRestClient;
Expand Down