Skip to content

Commit

Permalink
Implement add new contact
Browse files Browse the repository at this point in the history
  • Loading branch information
swanhtet1992 committed Jul 31, 2015
1 parent 00d3195 commit d526d88
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<activity android:name="org.mmaug.InfoCenter.activities.NewsDetailActivity" />

<activity android:name="org.mmaug.InfoCenter.activities.ReportActivity" />

<activity android:name="org.mmaug.InfoCenter.activities.AddContactActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.mmaug.InfoCenter.activities;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
import mmaug.org.yaybay.R;
import org.mmaug.InfoCenter.model.News;
import org.mmaug.InfoCenter.rest.client.RESTClient;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
* @author SH ([email protected])
*/
public class AddContactActivity extends AppCompatActivity {
@Bind(R.id.edt_title) EditText edtTitle;
@Bind(R.id.edt_fb_url) EditText edtFbUrl;
@Bind(R.id.edt_contact_number) EditText edtContactNumber;
@Bind(R.id.edt_detail) EditText edtDetail;
@Bind(R.id.edt_donation_location) EditText edtLocation;

@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_contact);
ButterKnife.bind(this);
}

public void onSubmit(View view) {
if (TextUtils.isEmpty(edtTitle.getText())
|| TextUtils.isEmpty(edtFbUrl.getText())
|| TextUtils.isEmpty(edtContactNumber.getText())) {
Toast.makeText(this, "Please write at least contact number", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Loading...", Toast.LENGTH_SHORT).show();
String title = edtTitle.getText().toString();
String fb = edtFbUrl.getText().toString();
String content = edtDetail.getText().toString();
String ph = edtContactNumber.getText().toString();
String location = edtLocation.getText().toString();

RESTClient.getInstance()
.getService()
.submitContact(title, content, fb, location, ph, new Callback<News>() {
@Override public void success(News news, Response response) {
Toast.makeText(getApplicationContext(), "Submitted", Toast.LENGTH_SHORT).show();
finish();
}

@Override public void failure(RetrofitError error) {

}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ItemDecoration;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import java.util.ArrayList;
import mmaug.org.yaybay.R;
import org.mmaug.InfoCenter.adapter.ContactAdapter;
import org.mmaug.InfoCenter.base.BaseListActivity;
import org.mmaug.InfoCenter.model.Contact;
Expand Down Expand Up @@ -95,4 +98,23 @@ private void loadData() {

startActivity(i);
}

@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_contact, menu);
return true;
}

@Override public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_add) {
Intent i = new Intent();
i.setClass(this, AddContactActivity.class);

startActivity(i);
return true;
}

return super.onOptionsItemSelected(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import mmaug.org.yaybay.R;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -33,4 +34,8 @@ public void reportClick(View view) {

startActivity(i);
}

public void alertLevel(View view) {
Toast.makeText(this, "We will implement it tonight...", Toast.LENGTH_SHORT).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public interface RESTService {

@FormUrlEncoded @POST("/newsfeeds") void submitNews(@Field("title") String title,
@Field("description") String description, Callback<News> callback);

@FormUrlEncoded @POST("/donation_groups") void submitContact(@Field("title") String title,
@Field("description") String description, @Field("facebook_url") String fb,
@Field("donation_location") String location, @Field("phone_numbers") String phone,
Callback<News> callback);
}
54 changes: 54 additions & 0 deletions app/src/main/res/layout/activity_add_contact.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<EditText
android:id="@+id/edt_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_title"
android:minLines="3" />

<EditText
android:id="@+id/edt_fb_url"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_fb_url"
android:inputType="textUri" />

<EditText
android:id="@+id/edt_contact_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_contact_numbers"
android:minLines="3" />

<EditText
android:id="@+id/edt_detail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_detail"
android:minLines="5" />

<EditText
android:id="@+id/edt_donation_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_location"
android:minLines="5" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:onClick="onSubmit"
android:text="@string/btn_submit" />

</LinearLayout>
</ScrollView>
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:layout_column="1"
android:layout_row="0"
android:background="@color/red"
android:onClick="alertLevel"
android:text="@string/str_alert_level" />

<org.mmaug.InfoCenter.widgets.ZgTextView
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/menu/menu_contact.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_add"
android:title="Add Contact"
app:showAsAction="always" />
</menu>
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@

<string name="hint_title">Title</string>
<string name="hint_content">Content</string>
<string name="hint_fb_url">Facebook URL</string>
<string name="hint_contact_numbers">Contact Phone Numbers</string>
<string name="hint_detail">Detail</string>
<string name="hint_location">Donation Location</string>

<string name="btn_submit">Submit</string>
<string name="title_activity_main2">Main2Activity</string>

<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>

0 comments on commit d526d88

Please sign in to comment.