-
-
Notifications
You must be signed in to change notification settings - Fork 45
Ignoring all corrupt opportunities to show #2995
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
Changes from all commits
4a40d19
ea89121
e341068
dba5628
d3de1e2
282cdb9
e764235
7d90f3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:id="@+id/rootCardView" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginHorizontal="16dp" | ||
| android:layout_marginTop="8dp" | ||
| android:layout_marginBottom="8dp" | ||
| android:clickable="true" | ||
| android:focusable="true" | ||
| android:foreground="?android:attr/selectableItemBackground" | ||
| android:shadowColor="@color/connect_light_grey_transparent" | ||
| android:shadowDx="30" | ||
| android:shadowDy="30" | ||
| android:shadowRadius="50" | ||
| app:cardBackgroundColor="@color/connect_red" | ||
| app:cardCornerRadius="12dp" | ||
| app:cardElevation="5dp"> | ||
|
|
||
| <androidx.constraintlayout.widget.ConstraintLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:padding="18dp"> | ||
|
|
||
| <org.commcare.views.connect.connecttextview.ConnectMediumTextView | ||
| android:id="@+id/tvTitle" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:lineSpacingExtra="5dp" | ||
| android:minLines="1" | ||
| android:textColor="@color/black" | ||
| android:textSize="14sp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toTopOf="parent" /> | ||
|
|
||
| <org.commcare.views.connect.connecttextview.ConnectMediumTextView | ||
| android:id="@+id/tvDescription" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:lineSpacingExtra="5dp" | ||
| android:layout_marginTop="2dp" | ||
| android:minLines="1" | ||
| android:text="@string/connect_corrupt_job_text" | ||
| android:textColor="@color/black" | ||
| android:textSize="12sp" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toBottomOf="@+id/tvTitle" /> | ||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
|
|
||
| </androidx.cardview.widget.CardView> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
|
|
||
| import android.content.Context; | ||
| import android.os.Bundle; | ||
| import android.os.Handler; | ||
| import android.os.Looper; | ||
| import android.view.LayoutInflater; | ||
| import android.view.Menu; | ||
| import android.view.MenuInflater; | ||
|
|
@@ -55,7 +57,6 @@ | |
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.text.ParseException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.Date; | ||
|
|
@@ -72,6 +73,7 @@ public class ConnectJobsListsFragment extends Fragment { | |
| private TextView updateText; | ||
| private IConnectAppLauncher launcher; | ||
| ArrayList<ConnectLoginJobListModel> jobList; | ||
| ArrayList<ConnectLoginJobListModel> corruptJobs = new ArrayList<>(); | ||
| View view; | ||
|
|
||
|
|
||
|
|
@@ -133,6 +135,7 @@ public void onResume() { | |
| } | ||
|
|
||
| public void refreshData() { | ||
| corruptJobs.clear(); | ||
| ApiConnect.getConnectOpportunities(getContext(), new IApiCallback() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1g5 Sorry I didn't get you. Which
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They both are in different fragment so not sure if we can use that. Already code is separate originally. |
||
| @Override | ||
| public void processSuccess(int responseCode, InputStream responseData) { | ||
|
|
@@ -146,17 +149,24 @@ public void processSuccess(int responseCode, InputStream responseData) { | |
| JSONArray json = new JSONArray(responseAsString); | ||
| List<ConnectJobRecord> jobs = new ArrayList<>(json.length()); | ||
| for (int i = 0; i < json.length(); i++) { | ||
| JSONObject obj = (JSONObject) json.get(i); | ||
| jobs.add(ConnectJobRecord.fromJson(obj)); | ||
| JSONObject obj=null; | ||
| try { | ||
| obj = (JSONObject)json.get(i); | ||
| jobs.add(ConnectJobRecord.fromJson(obj)); | ||
| }catch (JSONException e) { | ||
| Logger.exception("Parsing return from Opportunities request", e); | ||
| handleCorruptJob(obj); | ||
| } | ||
| } | ||
|
|
||
| //Store retrieved jobs | ||
| totalJobs = jobs.size(); | ||
| newJobs = ConnectJobUtils.storeJobs(getContext(), jobs, true); | ||
| setJobListData(jobs); | ||
| } | ||
| } catch (IOException | JSONException | ParseException e) { | ||
| Logger.exception("Parsing return from Opportunities request", e); | ||
| } catch (IOException | JSONException e) { | ||
| Logger.exception("Parsing / database error return from Opportunities request", e); | ||
shubham1g5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw new RuntimeException(e); | ||
|
Comment on lines
+167
to
+169
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we only want to crash for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1g5 You are right for other cases but here IOException is raised if any error while reading the network response so I think we should include it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that signifies an error in network stream which should not be related to our application logic. |
||
| } | ||
|
|
||
| reportApiCall(true, totalJobs, newJobs); | ||
|
|
@@ -202,6 +212,16 @@ private void refreshUi() { | |
| } | ||
| } | ||
|
|
||
| private void handleCorruptJob(JSONObject obj) { | ||
| if(obj!=null) { | ||
| try { | ||
| corruptJobs.add(createJobModel(ConnectJobRecord.corruptJobfromJson(obj))); | ||
| } catch (JSONException e) { | ||
| Logger.exception("JSONException while retrieving corrupt opportunity title", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void updateSecondaryPhoneConfirmationTile(Context context) { | ||
| boolean show = ConnectManager.shouldShowSecondaryPhoneConfirmationTile(context); | ||
|
|
||
|
|
@@ -220,9 +240,9 @@ private void initRecyclerView() { | |
| RecyclerView rvJobList = view.findViewById(R.id.rvJobList); | ||
|
|
||
| TextView noJobsText = view.findViewById(R.id.connect_no_jobs_text); | ||
| noJobsText.setVisibility(jobList.size() > 0 ? View.GONE : View.VISIBLE); | ||
| noJobsText.setVisibility((corruptJobs.size()>0 || jobList.size() > 0) ? View.GONE : View.VISIBLE); | ||
|
|
||
| JobListConnectHomeAppsAdapter adapter = new JobListConnectHomeAppsAdapter(getContext(), jobList, (job, isLearning, appId, jobType) -> { | ||
| JobListConnectHomeAppsAdapter adapter = new JobListConnectHomeAppsAdapter(getContext(), jobList,corruptJobs, (job, isLearning, appId, jobType) -> { | ||
| if (jobType.equals(JOB_NEW_OPPORTUNITY)) { | ||
| launchJobInfo(job); | ||
| } else { | ||
|
|
@@ -354,6 +374,15 @@ private ConnectLoginJobListModel createJobModel( | |
| ); | ||
| } | ||
|
|
||
| private ConnectLoginJobListModel createJobModel( // Keeping only title as of now as other information might be corrupt | ||
| ConnectJobRecord job | ||
| ) { | ||
| return new ConnectLoginJobListModel( | ||
| job.getTitle(), | ||
| job | ||
| ); | ||
| } | ||
|
|
||
| private String getAppIdForType(ConnectJobRecord job, String jobType) { | ||
| return jobType.equalsIgnoreCase(JOB_LEARNING) | ||
| ? job.getLearnAppInfo().getAppId() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,15 +86,20 @@ public void processSuccess(int responseCode, InputStream responseData) { | |
| JSONArray json = new JSONArray(responseAsString); | ||
| List<ConnectJobRecord> jobs = new ArrayList<>(json.length()); | ||
| for (int i = 0; i < json.length(); i++) { | ||
| JSONObject obj = (JSONObject) json.get(i); | ||
| ConnectJobRecord job = ConnectJobRecord.fromJson(obj); | ||
| jobs.add(job); | ||
| try { | ||
| JSONObject obj = (JSONObject) json.get(i); | ||
| ConnectJobRecord job = ConnectJobRecord.fromJson(obj); | ||
| jobs.add(job); | ||
| }catch (JSONException e) { | ||
| Logger.exception("Parsing return from Opportunities request", e); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this mean we would swallow exception without showing any errors to the user ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1g5 Here, there is no UI to display and code is just retrieving opportunities only to store locally. Also, local store should only have good opportunities and not corrupt ones.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree on DB containing only good opportunities. I am trying to think if it's possible for user to not see an error on jobs list page when there is a corrupt opportunity in the response here ? For eg. it would be confusing if the corrupt opportunity shows only some times on UI and not all times due to us reusing the stored jobs list from DB that doesn't have corrupt opportunities.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In both cases, DB has good jobs only. ConnectUnlockFragment is not showing any UI for opportunities. |
||
| } | ||
| } | ||
| new JobStoreManager(requireContext()).storeJobs(requireContext(), jobs, true); | ||
| } | ||
| } catch (IOException | JSONException | ParseException e) { | ||
| } catch (IOException | JSONException e) { | ||
| Toast.makeText(requireContext(), R.string.connect_job_list_api_failure, Toast.LENGTH_SHORT).show(); | ||
| Logger.exception("Parsing return from Opportunities request", e); | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| setFragmentRedirection(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.