private void inflateCandidateSearchAdapter(String searchName) {
    Map<String, Integer> limitParams = new HashMap<>();
    limitParams.put("limit", 20);
    Call<ArrayList<CandidateSearchResult>> candidateAutoSearch =
        RESTClient.getService(this).searchCandidate(searchName, limitParams);
    candidateAutoSearch.enqueue(
        new RestCallback<ArrayList<CandidateSearchResult>>() {
          @Override
          public void onResponse(Response<ArrayList<CandidateSearchResult>> response) {
            candidateSearchResults.clear();
            candidateSearchResults.addAll(response.body());
            candidateSearchAdapter.setCandidates(candidateSearchResults);
            candidateSearchAdapter.notifyDataSetChanged();

            int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.spacing_micro);
            mCandidateListRecyclerView.setHasFixedSize(true);
            mCandidateListRecyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
            mCandidateListRecyclerView.setAdapter(candidateSearchAdapter);
            MixUtils.toggleVisibilityWithAnim(mCandidateListRecyclerView, true);
            mProgressBar.setVisibility(View.GONE);
            if (candidateSearchResults.size() == 0) {
              MixUtils.toggleVisibilityWithAnim(mErrorView, true);
            } else {
              MixUtils.toggleVisibilityWithAnim(mErrorView, false);
            }
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_candidate_detail);
    ButterKnife.bind(this);
    // actionbar
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("");

    typefaceTitle = FontCache.getTypefaceTitle(this);
    typefacelight = FontCache.getTypefaceTitle(this);
    isUnicode = UserPrefUtils.getInstance(this).getTextPref().equals(Config.UNICODE);

    mListener =
        new AppBarLayout.OnOffsetChangedListener() {
          @Override
          public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (collapsingAvatarToolbar.getHeight() + verticalOffset
                < 2 * ViewCompat.getMinimumHeight(collapsingAvatarToolbar)) {
              MixUtils.toggleVisibilityWithAnim(cardView, 1000, false);
            } else {
              MixUtils.toggleVisibilityWithAnim(cardView, 1000, true);
            }
          }
        };

    appbar.addOnOffsetChangedListener(mListener);

    candidate = (Candidate) getIntent().getSerializableExtra(Config.CANDIDATE);
    candidateSearchResult =
        (CandidateSearchResult) getIntent().getSerializableExtra("searchResult");

    if (candidate != null) {
      Glide.with(this)
          .load(candidate.getParty().getPartyFlag())
          .bitmapTransform(new BlurTransformation(getApplicationContext(), 8, 1))
          .into(partyImage);

      Glide.with(this)
          .load(candidate.getPhotoUrl())
          .diskCacheStrategy(DiskCacheStrategy.ALL)
          .bitmapTransform(new CropCircleTransformation(this))
          .placeholder(R.drawable.profile_placeholder)
          .into(candidateImage);
      candidateName.setText(candidate.getName());

      Glide.with(this)
          .load(candidate.getParty().getPartyFlag())
          .diskCacheStrategy(DiskCacheStrategy.ALL)
          .into(mCandidatePartyFlag);

      if (candidate.getConstituency().getAMPCODE() == null) {
        upperHouseView.setVisibility(View.GONE);
      } else {
        upperHouseView.setVisibility(View.VISIBLE);
        upperHouse.setText(
            MixUtils.amConstituencyName(
                candidate.getConstituency().getName(), candidate.getConstituency().getNumber()));
      }

      mCandidateConstituency.setText(candidate.getConstituency().getName());
      mCandidateDateOfBirth.setText(
          MixUtils.convertToBurmese(String.valueOf(candidate.getBirthDateString())));
      mCandidateEducation.setText(candidate.getEducation());
      mCandidateFather.setText(candidate.getFather().getName());
      mCandidateMother.setText(candidate.getMother().getName());
      mCandidateOccupation.setText(candidate.getOccupation());
      mCandidateRace.setText(candidate.getEthnicity());
      mCandidateReligion.setText(candidate.getReligion());
      mCandidateLegalSlature.setText(candidate.getLegislature());
      mCandidateParty.setText(candidate.getParty().getPartyName());
      mCandidateAddress.setText(candidate.getWardVillage());
      RESTService mRESTService = RESTClient.getService(this);
      if (candidate.getMpid() == null) {
        // mCompareCandidate.setCardBackgroundColor(getResources().getColor(R.color.accent_color_error));
        // mCandidateCompareResult.setText(getResources().getString(R.string.first_time_candidate));
        mQuestionHeaderTv.setVisibility(View.GONE);
        mMotionHeaderTv.setVisibility(View.GONE);
        mCandidateQuestionCard.setVisibility(View.GONE);
        mCandidateMotionCard.setVisibility(View.GONE);
      } else {

        Call<JsonObject> questionMotionCall =
            mRESTService.getQuestionAndMotion(candidate.getMpid());
        questionMotionCall.enqueue(
            new RestCallback<JsonObject>() {
              @Override
              public void onResponse(Response<JsonObject> response) {
                if (response.code() == 200) {
                  int motionCount = response.body().get("motions_count").getAsInt();
                  JsonArray motions = response.body().get("motions").getAsJsonArray();

                  int questionCount = response.body().get("questions_count").getAsInt();
                  JsonArray questions = response.body().get("questions").getAsJsonArray();

                  makeMotionChart(motionCount, motions);
                  makeQuestionChart(questionCount, questions);
                }
              }
            });
      }
    } else {
      // TODO fetch Candidate by ID
      /* RESTService mRESTService = RESTClient.getService(this);
      Map<String, String> amyotharParams = new HashMap<>();
      amyotharParams.put(Config.WITH, "party");
      Call<JsonObject> candidateCall =
          mRESTService.getCandidate("7abd75a22042fe8e3faf931d710949fe", amyotharParams);
      candidateCall.enqueue(new RestCallback<JsonObject>() {
        @Override public void onResponse(Response<JsonObject> response) {

        }
      });*/
    }

    mCompareCandidate.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(CandidateDetailActivity.this, CandidateListActivity.class);
            i.putExtra(Config.CANDIDATE, candidate);
            startActivity(i);
          }
        });

    setTypeFace();
  }
Beispiel #3
0
  @OnClick(R.id.sign_up_card)
  void checkVote() {
    if (!checkFieldisValid()) {
      Toast toast = new Toast(getActivity());
      TextView textView = new TextView(getActivity());
      textView.setText("အချက်အလက်များကို ပြည့်စုံစွာဖြည့်စွက်ပေးပါ");
      if (isUnicode) {
        textView.setTypeface(typefacelight);
      } else {
        MMTextUtils.getInstance(getContext()).prepareSingleView(textView);
      }
      textView.setPadding(16, 16, 16, 16);
      textView.setTextColor(Color.WHITE);
      textView.setBackgroundColor(getResources().getColor(R.color.accent_color));
      toast.setView(textView);
      toast.setGravity(Gravity.CENTER, 0, 10);
      toast.show();
    } else {
      MMTextUtils mmTextUtils = MMTextUtils.getInstance(getContext());
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append(mmTextUtils.zgToUni(mNrcNo.getText().toString()));
      stringBuilder.append("/");
      stringBuilder.append(mmTextUtils.zgToUni(mNrcTownShip.getText().toString()));
      stringBuilder.append("(နိုင်)");
      stringBuilder.append(mmTextUtils.zgToUni(mNrcValue.getText().toString()));
      String voterNrc = stringBuilder.toString();
      final Map<String, String> params = new HashMap<>();
      params.put(Config.VOTER_NAME, mmTextUtils.zgToUni(mUserName.getText().toString()));
      params.put(Config.DATE_OF_BIRTH, mDateOfBirth.getText().toString());
      params.put(Config.NRC, voterNrc);
      params.put(Config.FATHER_NAME, mmTextUtils.zgToUni(mFatherName.getText().toString()));
      params.put(Config.TOWNSHIP, mTownship.getText().toString());

      final Call<User> registerUser = RESTClient.getService(getActivity()).registerUser(params);
      registerUser.enqueue(
          new RestCallback<User>() {
            @Override
            public void onResponse(Response<User> response) {
              UserPrefUtils userPrefUtils = new UserPrefUtils(getActivity());
              if (response.code() == 200) {
                userPrefUtils.setValid(true);
              } else {
                userPrefUtils.setValid(false);
              }
              userPrefUtils.saveSkip(true);
              userPrefUtils.saveUserName(params.get(Config.VOTER_NAME));
              userPrefUtils.saveBirthDate(params.get(Config.DATE_OF_BIRTH));
              userPrefUtils.saveNRC(params.get(Config.NRC));
              userPrefUtils.saveFatherName(params.get(Config.FATHER_NAME));
              userPrefUtils.saveTownShip(townshipGson);
              mainView.setVisibility(View.GONE);
              contenFragment.setVisibility(View.VISIBLE);
              HomeFragment homeFragment = new HomeFragment();
              FragmentManager fm = getActivity().getSupportFragmentManager();
              FragmentTransaction transaction = fm.beginTransaction();
              transaction.replace(R.id.contentFragment, homeFragment);
              transaction.commit();
            }
          });
    }
  }