Skip to content

Commit

Permalink
unread msg count updates properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent Nguyen committed Dec 13, 2013
1 parent 1abec38 commit 43d29c1
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 121 deletions.
9 changes: 5 additions & 4 deletions PenPal/gen/edu/berkeley/cs160/off_by_1/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,10 @@ public static final class id {
public static final int image=0x7f070027;
public static final int imageView1=0x7f07004a;
public static final int kk=0x7f070065;
public static final int language=0x7f07005c;
public static final int language=0x7f07005d;
public static final int listMode=0x7f070001;
public static final int list_item=0x7f070029;
public static final int location=0x7f07005d;
public static final int location=0x7f07005c;
public static final int mainSpinner1=0x7f070067;
public static final int meetPenPalText=0x7f070055;
public static final int messageSent=0x7f070059;
Expand Down Expand Up @@ -1266,6 +1266,7 @@ public static final class string {
public static final int green=0x7f0c0030;
public static final int hello_user=0x7f0c001a;
public static final int home_button=0x7f0c0016;
public static final int internet_error=0x7f0c003f;
public static final int language=0x7f0c003c;
public static final int largesize=0x7f0c0038;
public static final int location=0x7f0c003b;
Expand All @@ -1278,7 +1279,7 @@ public static final class string {
public static final int red=0x7f0c002b;
public static final int reply_button=0x7f0c0026;
public static final int research_pen_pal=0x7f0c0028;
public static final int send_another=0x7f0c003f;
public static final int send_another=0x7f0c0040;
public static final int send_message_button=0x7f0c0029;
public static final int send_message_text=0x7f0c001f;
public static final int smallsize=0x7f0c0036;
Expand All @@ -1292,7 +1293,7 @@ public static final class string {
public static final int title_activity_receive_message=0x7f0c0011;
public static final int title_activity_send_message=0x7f0c0013;
public static final int to_user=0x7f0c0025;
public static final int undo=0x7f0c0040;
public static final int undo=0x7f0c0041;
public static final int user_profile=0x7f0c002a;
public static final int voice_message=0x7f0c0023;
public static final int yellow=0x7f0c002e;
Expand Down
100 changes: 53 additions & 47 deletions PenPal/res/layout/activity_meet_pen_pal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,58 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MeetPenPal" >

<TextView
android:id="@+id/meetPenPalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/new_pen_pal_text"
android:textSize="25sp" /><ImageView android:id="@+id/sun" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="10dp" android:adjustViewBounds="true" android:baselineAlignBottom="true" android:src="@drawable/sun" />

<TextView
android:id="@+id/penPalDetailsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="4"
android:layout_centerInParent="true"
android:layout_marginTop="15dp"
android:text=""
android:textSize="35sp"
android:textAlignment="center" />



<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<TextView
android:id="@+id/meetPenPalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/new_pen_pal_text"
android:textSize="25sp" />

<Button
style="@style/RedButton"
android:id="@+id/research"
android:layout_width="0dp"
android:layout_weight="1"
android:onClick="research"
android:layout_height="50dp"
android:text="@string/research_pen_pal" />
<ImageView
android:id="@+id/sun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:adjustViewBounds="true"
android:baselineAlignBottom="true"
android:src="@drawable/sun" />

<Button
style="@style/GreenButton"
android:id="@+id/sendMessage"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:text="@string/send_message_button"
android:onClick="goToSendMessage"
/>

</LinearLayout>

</RelativeLayout>
<TextView
android:id="@+id/penPalDetailsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/meetPenPalText"
android:layout_marginTop="25dp"
android:lines="4"
android:text=""
android:textAlignment="center"
android:textSize="30sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >

<Button
android:id="@+id/research"
style="@style/RedButton"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:onClick="research"
android:text="@string/research_pen_pal" />

<Button
android:id="@+id/sendMessage"
style="@style/GreenButton"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:onClick="goToSendMessage"
android:text="@string/send_message_button" />
</LinearLayout>

</RelativeLayout>
2 changes: 1 addition & 1 deletion PenPal/res/layout/activity_message_sent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/message_sent_text"
android:textSize="35sp" />
android:textSize="30sp" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
51 changes: 25 additions & 26 deletions PenPal/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,46 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Home" >

<TextView
android:id="@+id/profileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/language"
android:layout_alignParentTop="true"
android:layout_marginTop="21dp"
android:text="@string/user_profile"
android:textSize="20sp" />
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/profileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_profile"
android:layout_marginRight="30dp"
android:textSize="20sp" />

<ImageView
android:id="@+id/stamp"
android:layout_width="89dp"
android:layout_height="89dp"
android:layout_alignLeft="@+id/profileName"
android:layout_below="@+id/profileName"
android:layout_marginTop="21dp"

/>

<ImageView
android:id="@+id/stamp"
android:layout_width="89dp"
android:layout_height="89dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="21dp" />
</LinearLayout>

<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/friendListButton"
android:layout_below="@id/stamp"
android:layout_below="@+id/header"
android:layout_marginTop="28dp"
android:text="@string/location"
android:textSize="20sp" />
<TextView

<TextView
android:id="@+id/language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/friendListButton"
android:layout_below="@+id/location"
android:layout_marginTop="28dp"
android:text="@string/language"
android:textSize="20sp" />
<Button

<Button
android:id="@+id/friendListButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -58,4 +56,5 @@
android:layout_alignParentRight="true"
android:onClick="goToSendMessage"
android:text="@string/send_message_button" />

</RelativeLayout>
12 changes: 6 additions & 6 deletions PenPal/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<string name="friend_list_button">Friend\'s List</string>
<string name="friend_list_text">My Friends</string>
<string name="new_pen_pal_button">Make a New Pen Pal!</string>
<string name="new_pen_pal_text">Meet a New Pen Pal!</string>
<string name="new_pen_pal_text">Make a New Pen Pal!</string>
<string name="send_message_text">Send a message\n to %s!</string>
<string name="message_sent_text">Message been sent\n to\n %s!</string>
<string name="message_sent_text">I sent a message to\n %s!</string>
<string name="text_message">Write</string>
<string name="draw_message">Draw</string>
<string name="voice_message">Talk</string>
Expand All @@ -53,9 +53,9 @@
<string name="largesize">Large stroke</string>
<string name="erasers">Eraser</string>
<string name="stroke">Stroke</string>
<string name="location">Location From: %1$s</string>
<string name="language">Language: %1$s</string>
<string name="get_question_button"> Get a Question</string>
<string name="location">%1$s is from %2$s</string>
<string name="language">%1$s speaks %2$s</string>
<string name="get_question_button">Throw me a question!</string>
<string name="received_message"> Hi Jack Jack,\n How are you doing today?</string>
<string-array name="suggested_questions">
<item>What are you learning in school? </item>
Expand All @@ -78,7 +78,7 @@


</string-array>

<string name="internet_error">"I need the internet on to work"</string>
<string name="send_another">Send Another</string>
<string name="undo">undo</string>

Expand Down
23 changes: 0 additions & 23 deletions PenPal/src/edu/berkeley/cs160/off_by_1/FriendList.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,8 @@ public void goToSendMessage() {
}

public void goToProfile(View v) {

//Log.d("debug", profileName);
//goToProfile(profileName);
Intent i = new Intent(this, Profile.class);
Button buttonV = (Button) v;
Object[] data = getUserData(buttonV);
//Log.d("debug", "data" + data[0] + data[1] + data[2]);
String profileName = buttonV.getText().toString();
byte[] compressStamp = getUserStamp(buttonV);
i.putExtra("name", profileName);
Expand All @@ -110,22 +105,4 @@ private byte[] getUserStamp(Button v) {
return compressStamp;
}

/*void goToProfile(String name) {
Intent i = new Intent(this, Profile.class);
String[] data = getUserData(name);
Log.d("debug", "data" + data[0] + data[1] + data[2]);
i.putExtra("name", data);
startActivityForResult(i, 0);
}*/

private String[] getUserData(Button v) {
String profileName = v.getText().toString();
Drawable stamp = ((Button) v).getBackground();
String[] data = new String[3];
data[0] = profileName;
data[1] = "Spain";
data[2] = "English, Spanish";
return data;
}

}
34 changes: 26 additions & 8 deletions PenPal/src/edu/berkeley/cs160/off_by_1/Home.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package edu.berkeley.cs160.off_by_1;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;

import android.support.v7.app.ActionBarActivity;
Expand All @@ -15,43 +18,58 @@
import android.widget.TextView;

public class Home extends ActionBarActivity {
List<String> unreadMessages = new ArrayList<String>();
int unreadMsgCount;
String unreadMsgString;
TextView unreadMessagesText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
unreadMessages.add("Timmy");
unreadMessages.add("Annie");

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

//R.id.unreadText
int unreadMessages = 2;
String unreadMsgString = getResources().getQuantityString(R.plurals.unread_messages, unreadMessages, unreadMessages);
TextView unreadMessagesText = (TextView) findViewById(R.id.unreadText);
unreadMessagesText.setText(unreadMsgString);
updateUnreadMsgCount();
}

private void updateUnreadMsgCount() {
unreadMsgCount = unreadMessages.size();
unreadMsgString = getResources().getQuantityString(R.plurals.unread_messages, unreadMsgCount, unreadMsgCount);
unreadMessagesText = (TextView) findViewById(R.id.unreadText);
unreadMessagesText.setText(unreadMsgString);
}

@Override
public void onActivityResult(int req, int result, Intent i) {
Log.d("debug", "Got here" );
try {
String name = i.getStringExtra("name");

unreadMessages.remove(name);

Button openedMsg = null;
Drawable stamp;
Log.d("debug", "received name" + name);
if (name.equals("Timmy")) {
openedMsg = (Button) findViewById(R.id.timmy);

} else if (name.equals("Annie")) {
openedMsg = (Button) findViewById(R.id.annie);
}
stamp = openedMsg.getCompoundDrawables()[2];
Drawable openedImage = getResources().getDrawable(R.drawable.opened_message);
Log.d("debug", "opened image" + openedImage);

openedMsg.setCompoundDrawablesWithIntrinsicBounds(openedImage, null, stamp, null);

updateUnreadMsgCount();
} catch (Exception e) {

}
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand Down
Loading

0 comments on commit 43d29c1

Please sign in to comment.