{"action":"created","comment":{"url":"https://api.github.com/repos/openMF/android-client/pulls/comments/61066634","id":61066634,"diff_hunk":"@@ -0,0 +1,245 @@\n+/*\n+ * This project is licensed under the open source MPL V2.\n+ * See https://github.com/openMF/android-client/blob/master/LICENSE.md\n+ */\n+\n+package com.mifos.mifosxdroid.dialogfragments;\n+\n+import android.app.Dialog;\n+import android.os.Bundle;\n+import android.support.v4.app.DialogFragment;\n+import android.util.Log;\n+import android.view.LayoutInflater;\n+import android.view.View;\n+import android.view.ViewGroup;\n+import android.widget.AdapterView;\n+import android.widget.ArrayAdapter;\n+import android.widget.Button;\n+import android.widget.EditText;\n+import android.widget.Spinner;\n+import android.widget.Toast;\n+\n+import com.mifos.App;\n+import com.mifos.mifosxdroid.R;\n+import com.mifos.mifosxdroid.core.ProgressableDialogFragment;\n+import com.mifos.mifosxdroid.uihelpers.MFDatePicker;\n+import com.mifos.objects.Changes;\n+import com.mifos.objects.accounts.savings.Charge;\n+import com.mifos.objects.client.Charges;\n+import com.mifos.services.data.ChargesPayload;\n+import com.mifos.utils.Constants;\n+import com.mifos.utils.DateHelper;\n+import com.mifos.utils.FragmentConstants;\n+import com.mifos.utils.SafeUIBlockingUtility;\n+\n+import org.json.JSONArray;\n+import org.json.JSONObject;\n+\n+import java.io.BufferedReader;\n+import java.io.InputStreamReader;\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+\n+import butterknife.ButterKnife;\n+import butterknife.InjectView;\n+import retrofit.Callback;\n+import retrofit.RetrofitError;\n+import retrofit.client.Response;\n+\n+/**\n+ * Created by nellyk on 1/22/2016.\n+ * <p/>\n+ * Use this Dialog Fragment to Create and/or Update charges\n+ */\n+public class SavingsChargeDialogFragment extends ProgressableDialogFragment implements MFDatePicker.OnDatePickListener {\n+\n+    public static final String TAG = \"SavingsChargeFragment\";\n+    View rootView;\n+    SafeUIBlockingUtility safeUIBlockingUtility;\n+\n+    @InjectView(R.id.sp_charge_name)\n+    Spinner sp_charge_name;\n+    @InjectView(R.id.amount_due_charge)\n+    EditText et_amout_due;\n+    @InjectView(R.id.et_date)\n+    EditText charge_due_date;\n+    @InjectView(R.id.et_charge_locale)\n+    EditText charge_locale;\n+    @InjectView(R.id.bt_save_charge)\n+    Button bt_save_charge;\n+    private DialogFragment mfDatePicker;\n+    private int Id;\n+    private int savingsAccountNumber;\n+    String duedateString;\n+    private HashMap<String, Integer> chargeNameIdHashMap = new HashMap<String, Integer>();\n+    private String chargeName;\n+\n+    public static SavingsChargeDialogFragment newInstance(int savingsAccountNumber) {\n+        SavingsChargeDialogFragment savingsChargeDialogFragment = new SavingsChargeDialogFragment();\n+        Bundle args = new Bundle();\n+        args.putInt(Constants.SAVINGS_ACCOUNT_NUMBER, savingsAccountNumber);\n+        savingsChargeDialogFragment.setArguments(args);\n+        return savingsChargeDialogFragment;\n+    }\n+\n+    @Override\n+    public void onCreate(Bundle savedInstanceState) {\n+        super.onCreate(savedInstanceState);\n+        if (getArguments() != null)\n+            savingsAccountNumber = getArguments().getInt(Constants.SAVINGS_ACCOUNT_NUMBER);\n+    }\n+\n+    @Override\n+    public Dialog onCreateDialog(Bundle savedInstanceState) {\n+\n+        if (getArguments() != null)\n+            savingsAccountNumber = getArguments().getInt(Constants.SAVINGS_ACCOUNT_NUMBER);\n+        return super.onCreateDialog(savedInstanceState);\n+    }\n+\n+    @Override\n+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\n+\n+        // Inflate the layout for this fragment\n+        if (getActivity().getActionBar() != null)\n+            getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);\n+        rootView = inflater.inflate(R.layout.dialog_fragment_charge, null);\n+        ButterKnife.inject(this, rootView);\n+        inflatedueDate();\n+        inflateChargesSpinner();\n+\n+        duedateString = charge_due_date.getText().toString();\n+        duedateString = DateHelper.getDateAsStringUsedForCollectionSheetPayload(duedateString).replace(\"-\", \" \");\n+\n+        bt_save_charge.setOnClickListener(new View.OnClickListener() {\n+            @Override\n+            public void onClick(View view) {\n+\n+                ChargesPayload chargesPayload = new ChargesPayload();\n+                chargesPayload.setAmount(et_amout_due.getEditableText().toString());\n+                chargesPayload.setLocale(charge_locale.getEditableText().toString());\n+                chargesPayload.setDueDate(duedateString);\n+                chargesPayload.setDateFormat(\"dd MMMM yyyy\");\n+                chargesPayload.setChargeId(Id);\n+                initiateChargesCreation(chargesPayload);\n+            }\n+        });\n+        return rootView;\n+    }\n+\n+    @Override\n+    public void onDatePicked(String date) {\n+        charge_due_date.setText(date);\n+    }\n+\n+    private void inflateChargesSpinner() {\n+        showProgress(true);\n+        App.apiManager.getAllSavingsCharges(savingsAccountNumber,new Callback<Response>() {\n+\n+            @Override\n+            public void success(final Response result, Response response) {\n+                /* Activity is null - Fragment has been detached; no need to do anything. */\n+                if (getActivity() == null) return;\n+                Log.d(TAG, \"\");\n+\n+                final List<Charges> charges = new ArrayList<>();\n+                // you can use this array to populate your spinner\n+                final ArrayList<String> chargesNames = new ArrayList<String>();\n+                //Try to get response body\n+                BufferedReader reader = null;\n+                StringBuilder sb = new StringBuilder();\n+                try {\n+                    reader = new BufferedReader(new InputStreamReader(result.getBody().in()));\n+                    String line;\n+                    while ((line = reader.readLine()) != null) {\n+                        sb.append(line);\n+                    }\n+                    JSONObject obj = new JSONObject(sb.toString());\n+                    if (obj.has(\"chargeOptions\")) {\n+                        JSONArray chargesTypes = obj.getJSONArray(\"chargeOptions\");\n+                        for (int i = 0; i < chargesTypes.length(); i++) {\n+                            JSONObject chargesObject = chargesTypes.getJSONObject(i);\n+                            Charges charge = new Charges();\n+                            charge.setId(chargesObject.optInt(\"id\"));\n+                            charge.setName(chargesObject.optString(\"name\"));\n+                            charges.add(charge);\n+                            chargesNames.add(chargesObject.optString(\"name\"));\n+                            chargeNameIdHashMap.put(charge.getName(), charge.getId());\n+                        }\n+\n+                    }\n+                    String stringResult = sb.toString();\n+                } catch (Exception e) {\n+                    Log.e(TAG, \"\", e);\n+                }\n+                final ArrayAdapter<String> chargesAdapter = new ArrayAdapter<String>(getActivity(),\n+                        android.R.layout.simple_spinner_item, chargesNames);\n+                chargesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);\n+                sp_charge_name.setAdapter(chargesAdapter);\n+                sp_charge_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {\n+                    @Override\n+                    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {\n+                        Id = chargeNameIdHashMap.get(chargesNames.get(i));\n+                        Log.d(\"chargesoptionss\" + chargesNames.get(i), String.valueOf(Id));\n+                        if (Id != -1) {","path":"mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/SavingsChargeDialogFragment.java","position":185,"original_position":185,"commit_id":"784b8932f02253afe4897ec08480d9aa2516e7bd","original_commit_id":"784b8932f02253afe4897ec08480d9aa2516e7bd","user":{"login":"ishan1604","id":3158880,"avatar_url":"https://avatars.githubusercontent.com/u/3158880?v=3","gravatar_id":"","url":"https://api.github.com/users/ishan1604","html_url":"https://github.com/ishan1604","followers_url":"https://api.github.com/users/ishan1604/followers","following_url":"https://api.github.com/users/ishan1604/following{/other_user}","gists_url":"https://api.github.com/users/ishan1604/gists{/gist_id}","starred_url":"https://api.github.com/users/ishan1604/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ishan1604/subscriptions","organizations_url":"https://api.github.com/users/ishan1604/orgs","repos_url":"https://api.github.com/users/ishan1604/repos","events_url":"https://api.github.com/users/ishan1604/events{/privacy}","received_events_url":"https://api.github.com/users/ishan1604/received_events","type":"User","site_admin":false},"body":"Could you please explain the reason for this empty block?","created_at":"2016-04-26T11:00:42Z","updated_at":"2016-04-26T11:00:42Z","html_url":"https://github.com/openMF/android-client/pull/276#discussion_r61066634","pull_request_url":"https://api.github.com/repos/openMF/android-client/pulls/276","_links":{"self":{"href":"https://api.github.com/repos/openMF/android-client/pulls/comments/61066634"},"html":{"href":"https://github.com/openMF/android-client/pull/276#discussion_r61066634"},"pull_request":{"href":"https://api.github.com/repos/openMF/android-client/pulls/276"}}},"pull_request":{"url":"https://api.github.com/repos/openMF/android-client/pulls/276","id":67836152,"html_url":"https://github.com/openMF/android-client/pull/276","diff_url":"https://github.com/openMF/android-client/pull/276.diff","patch_url":"https://github.com/openMF/android-client/pull/276.patch","issue_url":"https://api.github.com/repos/openMF/android-client/issues/276","number":276,"state":"open","locked":false,"title":"MIFOSAC-127: Add ability to add charges to a savings account","user":{"login":"chegz254","id":5506316,"avatar_url":"https://avatars.githubusercontent.com/u/5506316?v=3","gravatar_id":"","url":"https://api.github.com/users/chegz254","html_url":"https://github.com/chegz254","followers_url":"https://api.github.com/users/chegz254/followers","following_url":"https://api.github.com/users/chegz254/following{/other_user}","gists_url":"https://api.github.com/users/chegz254/gists{/gist_id}","starred_url":"https://api.github.com/users/chegz254/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chegz254/subscriptions","organizations_url":"https://api.github.com/users/chegz254/orgs","repos_url":"https://api.github.com/users/chegz254/repos","events_url":"https://api.github.com/users/chegz254/events{/privacy}","received_events_url":"https://api.github.com/users/chegz254/received_events","type":"User","site_admin":false},"body":"Copied working code from old branch to new branch. The previous branch contained code for other tasks, which interfered with the main code.","created_at":"2016-04-26T07:04:51Z","updated_at":"2016-04-26T11:00:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f5b9a813725487e948814831e5cb70c0dfe61b39","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openMF/android-client/pulls/276/commits","review_comments_url":"https://api.github.com/repos/openMF/android-client/pulls/276/comments","review_comment_url":"https://api.github.com/repos/openMF/android-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openMF/android-client/issues/276/comments","statuses_url":"https://api.github.com/repos/openMF/android-client/statuses/784b8932f02253afe4897ec08480d9aa2516e7bd","head":{"label":"chegz254:savings-charges","ref":"savings-charges","sha":"784b8932f02253afe4897ec08480d9aa2516e7bd","user":{"login":"chegz254","id":5506316,"avatar_url":"https://avatars.githubusercontent.com/u/5506316?v=3","gravatar_id":"","url":"https://api.github.com/users/chegz254","html_url":"https://github.com/chegz254","followers_url":"https://api.github.com/users/chegz254/followers","following_url":"https://api.github.com/users/chegz254/following{/other_user}","gists_url":"https://api.github.com/users/chegz254/gists{/gist_id}","starred_url":"https://api.github.com/users/chegz254/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chegz254/subscriptions","organizations_url":"https://api.github.com/users/chegz254/orgs","repos_url":"https://api.github.com/users/chegz254/repos","events_url":"https://api.github.com/users/chegz254/events{/privacy}","received_events_url":"https://api.github.com/users/chegz254/received_events","type":"User","site_admin":false},"repo":{"id":55218403,"name":"android-client","full_name":"chegz254/android-client","owner":{"login":"chegz254","id":5506316,"avatar_url":"https://avatars.githubusercontent.com/u/5506316?v=3","gravatar_id":"","url":"https://api.github.com/users/chegz254","html_url":"https://github.com/chegz254","followers_url":"https://api.github.com/users/chegz254/followers","following_url":"https://api.github.com/users/chegz254/following{/other_user}","gists_url":"https://api.github.com/users/chegz254/gists{/gist_id}","starred_url":"https://api.github.com/users/chegz254/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chegz254/subscriptions","organizations_url":"https://api.github.com/users/chegz254/orgs","repos_url":"https://api.github.com/users/chegz254/repos","events_url":"https://api.github.com/users/chegz254/events{/privacy}","received_events_url":"https://api.github.com/users/chegz254/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chegz254/android-client","description":"An android client for the MifosX platform","fork":true,"url":"https://api.github.com/repos/chegz254/android-client","forks_url":"https://api.github.com/repos/chegz254/android-client/forks","keys_url":"https://api.github.com/repos/chegz254/android-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chegz254/android-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chegz254/android-client/teams","hooks_url":"https://api.github.com/repos/chegz254/android-client/hooks","issue_events_url":"https://api.github.com/repos/chegz254/android-client/issues/events{/number}","events_url":"https://api.github.com/repos/chegz254/android-client/events","assignees_url":"https://api.github.com/repos/chegz254/android-client/assignees{/user}","branches_url":"https://api.github.com/repos/chegz254/android-client/branches{/branch}","tags_url":"https://api.github.com/repos/chegz254/android-client/tags","blobs_url":"https://api.github.com/repos/chegz254/android-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chegz254/android-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chegz254/android-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/chegz254/android-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chegz254/android-client/statuses/{sha}","languages_url":"https://api.github.com/repos/chegz254/android-client/languages","stargazers_url":"https://api.github.com/repos/chegz254/android-client/stargazers","contributors_url":"https://api.github.com/repos/chegz254/android-client/contributors","subscribers_url":"https://api.github.com/repos/chegz254/android-client/subscribers","subscription_url":"https://api.github.com/repos/chegz254/android-client/subscription","commits_url":"https://api.github.com/repos/chegz254/android-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/chegz254/android-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/chegz254/android-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/chegz254/android-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/chegz254/android-client/contents/{+path}","compare_url":"https://api.github.com/repos/chegz254/android-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chegz254/android-client/merges","archive_url":"https://api.github.com/repos/chegz254/android-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chegz254/android-client/downloads","issues_url":"https://api.github.com/repos/chegz254/android-client/issues{/number}","pulls_url":"https://api.github.com/repos/chegz254/android-client/pulls{/number}","milestones_url":"https://api.github.com/repos/chegz254/android-client/milestones{/number}","notifications_url":"https://api.github.com/repos/chegz254/android-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chegz254/android-client/labels{/name}","releases_url":"https://api.github.com/repos/chegz254/android-client/releases{/id}","deployments_url":"https://api.github.com/repos/chegz254/android-client/deployments","created_at":"2016-04-01T09:03:38Z","updated_at":"2016-04-01T09:03:40Z","pushed_at":"2016-04-26T07:05:09Z","git_url":"git://github.com/chegz254/android-client.git","ssh_url":"git@github.com:chegz254/android-client.git","clone_url":"https://github.com/chegz254/android-client.git","svn_url":"https://github.com/chegz254/android-client","homepage":"","size":34577,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"ready"}},"base":{"label":"openMF:master","ref":"master","sha":"21e62c78a209f638ad62481447d152fd5255f24e","user":{"login":"openMF","id":3473607,"avatar_url":"https://avatars.githubusercontent.com/u/3473607?v=3","gravatar_id":"","url":"https://api.github.com/users/openMF","html_url":"https://github.com/openMF","followers_url":"https://api.github.com/users/openMF/followers","following_url":"https://api.github.com/users/openMF/following{/other_user}","gists_url":"https://api.github.com/users/openMF/gists{/gist_id}","starred_url":"https://api.github.com/users/openMF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openMF/subscriptions","organizations_url":"https://api.github.com/users/openMF/orgs","repos_url":"https://api.github.com/users/openMF/repos","events_url":"https://api.github.com/users/openMF/events{/privacy}","received_events_url":"https://api.github.com/users/openMF/received_events","type":"Organization","site_admin":false},"repo":{"id":18864134,"name":"android-client","full_name":"openMF/android-client","owner":{"login":"openMF","id":3473607,"avatar_url":"https://avatars.githubusercontent.com/u/3473607?v=3","gravatar_id":"","url":"https://api.github.com/users/openMF","html_url":"https://github.com/openMF","followers_url":"https://api.github.com/users/openMF/followers","following_url":"https://api.github.com/users/openMF/following{/other_user}","gists_url":"https://api.github.com/users/openMF/gists{/gist_id}","starred_url":"https://api.github.com/users/openMF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openMF/subscriptions","organizations_url":"https://api.github.com/users/openMF/orgs","repos_url":"https://api.github.com/users/openMF/repos","events_url":"https://api.github.com/users/openMF/events{/privacy}","received_events_url":"https://api.github.com/users/openMF/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openMF/android-client","description":"An android client for the MifosX platform","fork":false,"url":"https://api.github.com/repos/openMF/android-client","forks_url":"https://api.github.com/repos/openMF/android-client/forks","keys_url":"https://api.github.com/repos/openMF/android-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openMF/android-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openMF/android-client/teams","hooks_url":"https://api.github.com/repos/openMF/android-client/hooks","issue_events_url":"https://api.github.com/repos/openMF/android-client/issues/events{/number}","events_url":"https://api.github.com/repos/openMF/android-client/events","assignees_url":"https://api.github.com/repos/openMF/android-client/assignees{/user}","branches_url":"https://api.github.com/repos/openMF/android-client/branches{/branch}","tags_url":"https://api.github.com/repos/openMF/android-client/tags","blobs_url":"https://api.github.com/repos/openMF/android-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openMF/android-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openMF/android-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/openMF/android-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openMF/android-client/statuses/{sha}","languages_url":"https://api.github.com/repos/openMF/android-client/languages","stargazers_url":"https://api.github.com/repos/openMF/android-client/stargazers","contributors_url":"https://api.github.com/repos/openMF/android-client/contributors","subscribers_url":"https://api.github.com/repos/openMF/android-client/subscribers","subscription_url":"https://api.github.com/repos/openMF/android-client/subscription","commits_url":"https://api.github.com/repos/openMF/android-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/openMF/android-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/openMF/android-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/openMF/android-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/openMF/android-client/contents/{+path}","compare_url":"https://api.github.com/repos/openMF/android-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openMF/android-client/merges","archive_url":"https://api.github.com/repos/openMF/android-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openMF/android-client/downloads","issues_url":"https://api.github.com/repos/openMF/android-client/issues{/number}","pulls_url":"https://api.github.com/repos/openMF/android-client/pulls{/number}","milestones_url":"https://api.github.com/repos/openMF/android-client/milestones{/number}","notifications_url":"https://api.github.com/repos/openMF/android-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openMF/android-client/labels{/name}","releases_url":"https://api.github.com/repos/openMF/android-client/releases{/id}","deployments_url":"https://api.github.com/repos/openMF/android-client/deployments","created_at":"2014-04-17T02:35:44Z","updated_at":"2016-04-24T22:21:07Z","pushed_at":"2016-04-26T07:04:51Z","git_url":"git://github.com/openMF/android-client.git","ssh_url":"git@github.com:openMF/android-client.git","clone_url":"https://github.com/openMF/android-client.git","svn_url":"https://github.com/openMF/android-client","homepage":"","size":35166,"stargazers_count":26,"watchers_count":26,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":95,"mirror_url":null,"open_issues_count":29,"forks":95,"open_issues":29,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openMF/android-client/pulls/276"},"html":{"href":"https://github.com/openMF/android-client/pull/276"},"issue":{"href":"https://api.github.com/repos/openMF/android-client/issues/276"},"comments":{"href":"https://api.github.com/repos/openMF/android-client/issues/276/comments"},"review_comments":{"href":"https://api.github.com/repos/openMF/android-client/pulls/276/comments"},"review_comment":{"href":"https://api.github.com/repos/openMF/android-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openMF/android-client/pulls/276/commits"},"statuses":{"href":"https://api.github.com/repos/openMF/android-client/statuses/784b8932f02253afe4897ec08480d9aa2516e7bd"}}}}