Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new report submittion fragment #129

Merged
merged 15 commits into from
Dec 14, 2016
Merged
9 changes: 0 additions & 9 deletions app/src/main/java/lt/vilnius/tvarkau/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnLongClick;
import lt.vilnius.tvarkau.activity.ReportRegistrationActivity;
import lt.vilnius.tvarkau.utils.GlobalConsts;
import lt.vilnius.tvarkau.utils.PermissionUtils;
Expand Down Expand Up @@ -50,18 +49,10 @@ protected void startNewActivity(Class<?> cls, Bundle data) {

@OnClick(R.id.home_report_problem)
protected void onNewIssueClicked() {
Intent intent = new Intent(this, NewProblemActivity.class);
startActivityForResult(intent, NEW_ISSUE_REQUEST_CODE);
}

@OnLongClick(R.id.home_report_problem)
protected boolean onNewIssueLongClicked() {
Intent intent = new Intent(this, ReportRegistrationActivity.class);
startActivityForResult(intent, NEW_ISSUE_REQUEST_CODE);
return true;
}


@OnClick(R.id.home_list_of_problems)
protected void onProblemsListClicked() {
Intent intent = ProblemsListActivity.getStartActivityIntent(this, ALL_PROBLEMS);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/lt/vilnius/tvarkau/NewProblemActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

public class NewProblemActivity extends BaseActivity implements NewProblemPhotosPagerAdapter.OnPhotoClickedListener {

private static final int TAKE_PHOTO_PERMISSIONS_REQUEST_CODE = 10;
private static final int MAP_PERMISSION_REQUEST_CODE = 20;
public static final int TAKE_PHOTO_PERMISSIONS_REQUEST_CODE = 10;
public static final int MAP_PERMISSION_REQUEST_CODE = 20;

public static final int REQUEST_PLACE_PICKER = 11;
public static final int REQUEST_PERSONAL_DATA = 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@ package lt.vilnius.tvarkau.activity

import android.os.Bundle
import lt.vilnius.tvarkau.BaseActivity
import lt.vilnius.tvarkau.fragments.NewReportFragment
import lt.vilnius.tvarkau.fragments.ReportTypeListFragment

class ReportRegistrationActivity : BaseActivity() {
Copy link
Collaborator

@vycius vycius Dec 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing this PR got:

12-13 17:56:25.045 31875-31875/lt.vilnius.tvarkau E/WindowManager: android.view.WindowLeaked: Activity lt.vilnius.tvarkau.activity.ReportRegistrationActivity has leaked window DecorView@485b2d3[] that was originally added here
                                                                       at android.view.ViewRootImpl.<init>(ViewRootImpl.java:418)
                                                                       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
                                                                       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
                                                                       at android.app.Dialog.show(Dialog.java:322)
                                                                       at lt.vilnius.tvarkau.fragments.NewReportFragment.showProgress(NewReportFragment.kt:545)
                                                                       at lt.vilnius.tvarkau.mvp.presenters.NewReportPresenterImpl$submitProblem$3.call(NewReportPresenterImpl.kt:49)
                                                                       at rx.internal.operators.SingleDoOnSubscribe.call(SingleDoOnSubscribe.java:43)
                                                                       at rx.internal.operators.SingleDoOnSubscribe.call(SingleDoOnSubscribe.java:28)
                                                                       at rx.internal.operators.SingleDoOnUnsubscribe.call(SingleDoOnUnsubscribe.java:42)
                                                                       at rx.internal.operators.SingleDoOnUnsubscribe.call(SingleDoOnUnsubscribe.java:28)
                                                                       at rx.Single.subscribe(Single.java:1876)
                                                                       at rx.Single.subscribe(Single.java:1686)
                                                                       at lt.vilnius.tvarkau.mvp.presenters.NewReportPresenterImpl.submitProblem(NewReportPresenterImpl.kt:51)
                                                                       at lt.vilnius.tvarkau.fragments.NewReportFragment.onOptionsItemSelected(NewReportFragment.kt:156)
                                                                       at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2212)
                                                                       at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:2295)
                                                                       at android.support.v4.app.FragmentController.dispatchOptionsItemSelected(FragmentController.java:353)
                                                                       at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:414)
                                                                       at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:198)
                                                                       at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:107)
                                                                       at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:107)
                                                                       at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:69)
                                                                       at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:206)
                                                                       at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:777)
                                                                       at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:817)
                                                                       at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156)
                                                                       at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:964)
                                                                       at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:954)
                                                                       at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:624)
                                                                       at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:157)
                                                                       at android.view.View.performClick(View.java:5637)
                                                                       at android.view.View$PerformClick.run(View.java:22429)
                                                                       at android.os.Handler.handleCallback(Handler.java:751)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Device Nexus 5x newest Android version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, good catch


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(android.R.id.content, ReportTypeListFragment.newInstance())
.commit()
}
}

fun onTypeSelected(reportType: String) {
supportFragmentManager
.beginTransaction()
.replace(android.R.id.content, ReportTypeListFragment.newInstance())
.replace(android.R.id.content, NewReportFragment.newInstance(reportType))
.addToBackStack(null)
.commit()
}

fun onTypeSelected(reportType: String) {
//TODO next fragment
fun onReportSubmitted() {
setResult(RESULT_OK)
finish()
}

override fun onBackPressed() {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/lt/vilnius/tvarkau/backend/ApiRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package lt.vilnius.tvarkau.backend;

import android.support.annotation.VisibleForTesting;

public class ApiRequest<P> {

private String method;
Expand All @@ -11,4 +13,9 @@ public ApiRequest(ApiMethod method, P params) {
this.id = method.getId();
this.params = params;
}

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
public P getParams() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's only used for tests use VisibleForTesting

return params;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public GetNewProblemParams(String sessionId, String description, String type, St

}

public String[] getPhoto() {
return photo;
}

public static class Builder {
private String sessionId;
private String description;
Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/lt/vilnius/tvarkau/entity/Profile.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package lt.vilnius.tvarkau.entity;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;

import org.threeten.bp.LocalDate;

import lt.vilnius.tvarkau.utils.SharedPrefsManager;


public class Profile {

Expand Down Expand Up @@ -53,8 +47,16 @@ public String getMobilePhone() {
return mobilePhone;
}

public static Profile returnProfile(Context con) {
return SharedPrefsManager.getInstance(con).getUserProfile();
public void setBirthday(LocalDate birthday) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not needed you have all required data to pass to constructor

this.birthday = birthday;
}

public void setEmail(String email) {
this.email = email;
}

public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}

public String createJsonData() {
Expand All @@ -73,9 +75,9 @@ public boolean equals(Object o) {
Profile profile = (Profile) o;

return name.equals(profile.getName()) &&
birthday.equals(profile.getBirthday()) &&
email.equals(profile.getEmail()) &&
mobilePhone.equals(profile.getMobilePhone());
birthday.equals(profile.getBirthday()) &&
email.equals(profile.getEmail()) &&
mobilePhone.equals(profile.getMobilePhone());
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ abstract class BaseFragment : Fragment() {

analytics.trackCurrentFragment(activity, this)
}

override fun onDestroyView() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not need

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this one so in super child classes there were lint errors, that super is not called...

super.onDestroyView()
}
}
Loading