Example #1
0
  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    if (mChapterAdapter != null && mChapterAdapter.getCount() > 0) {
      outState.putParcelable(ARG_SELECTED_CHAPTER, mSelectedChapter);
    }
  }
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    try {
      FragmentActivity activity = getActivity();
      PackageInfo packageInfo =
          activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
      mVersion.setText(packageInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
  }
Example #3
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);

    mLocationComparator =
        new ChapterComparator(
            PrefUtils.getHomeChapterId(getActivity()), App.getInstance().getLastLocation());

    mChapterAdapter = new ChapterAdapter(getActivity(), R.layout.spinner_item_welcome);
    mChapterAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);

    if (savedInstanceState != null) {
      mSelectedChapter = savedInstanceState.getParcelable(ARG_SELECTED_CHAPTER);
    }

    App.getInstance()
        .getModelCache()
        .getAsync(
            Const.CACHE_KEY_CHAPTER_LIST_HUB,
            new ModelCache.CacheListener() {
              @Override
              public void onGet(Object item) {
                Directory directory = (Directory) item;
                if (isContextValid()) {
                  addChapters(directory.getGroups());
                  mLoadSwitcher.setDisplayedChild(1);
                }
              }

              @Override
              public void onNotFound(String key) {
                fetchChapters();
              }
            });

    mChapterSpinnerView.setThreshold(1);

    Filter.FilterListener enableConfirmOnUniqueFilterResult =
        new Filter.FilterListener() {
          @Override
          public void onFilterComplete(int count) {
            mConfirmButton.setEnabled(count == 1);
            if (count == 1) {
              mSelectedChapter = mChapterAdapter.getItem(0);
              updateAutoCompleteHint(mSelectedChapter);
              mChapterSpinnerView.dismissDropDown();
            } else if (count == 0 && hasTrailingSpace(mChapterSpinnerView)) {
              mChapterSpinnerTextInputLayout.setError(getString(R.string.remove_trailing_spaces));
            } else {
              resetAutoCompleteHint();
            }
          }
        };
    AdapterView.OnItemClickListener enableConfirmOnChapterClick =
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mConfirmButton.setEnabled(true);
            mSelectedChapter = mChapterAdapter.getItem(position);
            updateAutoCompleteHint(mSelectedChapter);
          }
        };

    mChapterSpinnerView.setFilterCompletionListener(enableConfirmOnUniqueFilterResult);
    mChapterSpinnerView.setOnItemClickListener(enableConfirmOnChapterClick);
    mChapterSpinnerView.setOnTouchListener(new ChapterSpinnerTouchListener());

    mChapterSpinnerTextInputLayout.setErrorEnabled(true);

    mConfirmButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (getActivity() instanceof Step1Listener) {
              // TODO re-order cached chapter list
              ((Step1Listener) getActivity()).onConfirmedChapter(mSelectedChapter);
            }
          }
        });
  }