From d526d880e97eca7f9624ee0b6406372a05ae60b7 Mon Sep 17 00:00:00 2001 From: SH Date: Sat, 1 Aug 2015 04:16:19 +0630 Subject: [PATCH] Implement add new contact --- app/src/main/AndroidManifest.xml | 2 + .../activities/AddContactActivity.java | 61 +++++++++++++++++++ .../activities/ContactsActivity.java | 22 +++++++ .../InfoCenter/activities/MainActivity.java | 5 ++ .../InfoCenter/rest/service/RESTService.java | 5 ++ .../main/res/layout/activity_add_contact.xml | 54 ++++++++++++++++ app/src/main/res/layout/activity_main.xml | 1 + app/src/main/res/menu/menu_contact.xml | 8 +++ app/src/main/res/values/strings.xml | 9 +++ 9 files changed, 167 insertions(+) create mode 100644 app/src/main/java/org/mmaug/InfoCenter/activities/AddContactActivity.java create mode 100644 app/src/main/res/layout/activity_add_contact.xml create mode 100644 app/src/main/res/menu/menu_contact.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ece7de6..c82710a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,8 @@ + + diff --git a/app/src/main/java/org/mmaug/InfoCenter/activities/AddContactActivity.java b/app/src/main/java/org/mmaug/InfoCenter/activities/AddContactActivity.java new file mode 100644 index 0000000..c73c05a --- /dev/null +++ b/app/src/main/java/org/mmaug/InfoCenter/activities/AddContactActivity.java @@ -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 (swanhtet@nexlabs.co) + */ +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() { + @Override public void success(News news, Response response) { + Toast.makeText(getApplicationContext(), "Submitted", Toast.LENGTH_SHORT).show(); + finish(); + } + + @Override public void failure(RetrofitError error) { + + } + }); + } + } +} diff --git a/app/src/main/java/org/mmaug/InfoCenter/activities/ContactsActivity.java b/app/src/main/java/org/mmaug/InfoCenter/activities/ContactsActivity.java index 8e0d851..346bb21 100644 --- a/app/src/main/java/org/mmaug/InfoCenter/activities/ContactsActivity.java +++ b/app/src/main/java/org/mmaug/InfoCenter/activities/ContactsActivity.java @@ -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; @@ -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); + } } diff --git a/app/src/main/java/org/mmaug/InfoCenter/activities/MainActivity.java b/app/src/main/java/org/mmaug/InfoCenter/activities/MainActivity.java index 8e9ca17..3d5ec63 100644 --- a/app/src/main/java/org/mmaug/InfoCenter/activities/MainActivity.java +++ b/app/src/main/java/org/mmaug/InfoCenter/activities/MainActivity.java @@ -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 { @@ -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(); + } } diff --git a/app/src/main/java/org/mmaug/InfoCenter/rest/service/RESTService.java b/app/src/main/java/org/mmaug/InfoCenter/rest/service/RESTService.java index cdc5533..47d5fe6 100644 --- a/app/src/main/java/org/mmaug/InfoCenter/rest/service/RESTService.java +++ b/app/src/main/java/org/mmaug/InfoCenter/rest/service/RESTService.java @@ -19,4 +19,9 @@ public interface RESTService { @FormUrlEncoded @POST("/newsfeeds") void submitNews(@Field("title") String title, @Field("description") String description, Callback 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 callback); } diff --git a/app/src/main/res/layout/activity_add_contact.xml b/app/src/main/res/layout/activity_add_contact.xml new file mode 100644 index 0000000..d0d544d --- /dev/null +++ b/app/src/main/res/layout/activity_add_contact.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + +