Esempio n. 1
0
 @Override
 public void onClick(View v) {
   textView.showDropDown();
   if (!((MainNavigationDrawer) getActivity()).isOnline())
     ((MainNavigationDrawer) getActivity()).askForInternet();
   else startDownloadListFaculties((ArrayAdapter<String>) textView.getAdapter());
 }
Esempio n. 2
0
 public void startDownloadListFaculties(ArrayAdapter<String> arrayAdapter) {
   if (!m_activeApp) {
     StaticStorage.m_listFaculties.clear();
     Thread thread;
     m_activeApp = true;
     m_download_finished = false;
     textView.setCompletionHint(getActivity().getString(R.string.placeholder_downloading));
     ServerGetFaculties serverGetFaclts =
         new ServerGetFaculties((ArrayAdapter<String>) textView.getAdapter());
     serverGetFaclts.execute();
     m_activeApp = true;
     thread =
         new Thread() {
           public void run() {
             try {
               while (!m_download_finished) {
                 Thread.sleep(200);
                 if (!textView.getAdapter().isEmpty()) {
                   textView.setCompletionHint("");
                   m_download_finished = true;
                 }
               } // while
             } catch (Exception ex) {
             }
           }
         };
     thread.start();
   }
 }
Esempio n. 3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the help for this fragment
    //        if(view == null)
    Log.d("init", "search fragment onCreateView");
    if (true) view = inflater.inflate(R.layout.fragment_search, container, false);
    if (true) {
      textView = (AutoCompleteTextView) view.findViewById(R.id.autocomplete_search);
      textView.setThreshold(1);

      if (mType == t_type.GROUP) {
        textView.setOnClickListener(this);
        textView.setOnItemClickListener(this);

        textView.setHint(R.string.group_search_placeholder);

        adapter =
            new ArrayAdapter<String>(
                getActivity(), R.layout.text_layout, StaticStorage.m_listGroupsName);
        textView.setAdapter(adapter);
        adapter.setNotifyOnChange(true);

        ListView list = (ListView) view.findViewById(R.id.recentList);
        final ArrayAdapter recent_adapter =
            new ArrayAdapter(
                inflater.getContext(),
                R.layout.detailed_item_list_item,
                new ArrayList(StaticStorage.m_recentGroups.values())) {
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                View holder;
                Group group = (Group) getItem(position);
                if (convertView == null) {
                  // You should fetch the LayoutInflater once in your constructor
                  holder =
                      LayoutInflater.from(parent.getContext())
                          .inflate(R.layout.detailed_item_list_item, parent, false);
                } else {
                  holder = convertView;
                }

                TextView v = (TextView) holder.findViewById(R.id.detailed_item_list_item_text1);
                v.setText(group.m_info.m_name);
                v = (TextView) holder.findViewById(R.id.detailed_item_list_item_text2);
                v.setText(group.m_info.m_faculty.m_abbr);
                v = (TextView) holder.findViewById(R.id.detailed_item_list_item_text3);
                v.setText(group.m_info.m_spec);
                return holder;
              }
            };
        list.setAdapter(recent_adapter);
        // ListView Item Click Listener
        list.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {

              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Group group = (Group) recent_adapter.getItem(position);

                Log.d("init", group.toString());
                if (((NavigationView) getActivity().findViewById(R.id.nav_view))
                    .getMenu()
                    .getItem(0)
                    .isChecked()) {
                  ((MainNavigationDrawer) getActivity()).createTree(group);
                  //                            new CreateFiles(getActivity(), group).execute();
                } else {
                  ((MainNavigationDrawer) getActivity())
                      .switchContent(TimeTableFragment.newInstance(group));
                  StaticStorage.m_recentGroups.put(group.m_info.m_id, group);
                }
              }
            });

        Button btn = (Button) view.findViewById(R.id.primat_list);
        btn.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (!((MainNavigationDrawer) getActivity()).isOnline()) {
                  ((MainNavigationDrawer) getActivity()).askForInternet();
                  return;
                }
                if (StaticStorage.m_primatGroupsName.isEmpty()) {
                  new AlertDialog.Builder(getActivity())
                      .setTitle(getResources().getString(R.string.error))
                      .setMessage(getResources().getString(R.string.not_loaded))
                      .setPositiveButton(android.R.string.ok, null) // dismisses by default
                      .create()
                      .show();
                  return;
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(getResources().getString(R.string.str_depth));
                builder.setIcon(R.drawable.logo_amd_mod);
                //                        ListView modeList = new ListView(getActivity());
                final ArrayAdapter<String> modeAdapter =
                    new ArrayAdapter<String>(
                        getActivity(),
                        android.R.layout.simple_list_item_1,
                        android.R.id.text1,
                        StaticStorage.m_primatGroupsName);
                builder.setAdapter(
                    modeAdapter,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        GroupInfo tmpGroup = StaticStorage.m_primatGroups.get(which);
                        new ServerGetTable(tmpGroup, getActivity()).execute();
                      }
                    });
                final Dialog dialog = builder.create();
                dialog.show();
              }
            });
        if (StaticStorage.m_listGroupsName.isEmpty()) {
          if (!((MainNavigationDrawer) getActivity()).isOnline())
            ((MainNavigationDrawer) getActivity()).askForInternet();
          else startDownloadListFaculties((ArrayAdapter<String>) textView.getAdapter());
        }

      } else {
        if (!((MainNavigationDrawer) getActivity()).isOnline())
          ((MainNavigationDrawer) getActivity()).askForInternet();
        textView.setOnItemClickListener(this);
        textView.setHint(R.string.lecturer_search_placeholder);
        adapter =
            new ArrayAdapter<String>(
                getActivity(), R.layout.text_layout, StaticStorage.m_listLecturerName);
        adapter.setNotifyOnChange(true);
        textView.setAdapter(adapter);
        textView.addTextChangedListener(this);

        ListView list = (ListView) view.findViewById(R.id.recentList);
        final ArrayAdapter recent_adapter =
            new ArrayAdapter(
                inflater.getContext(),
                R.layout.detailed_item_list_item,
                new ArrayList(StaticStorage.m_recentLecturers.values())) {
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                View holder;
                Lecturer group = (Lecturer) getItem(position);
                if (convertView == null) {
                  // You should fetch the LayoutInflater once in your constructor
                  holder =
                      LayoutInflater.from(parent.getContext())
                          .inflate(R.layout.detailed_item_list_item, parent, false);
                } else {
                  holder = convertView;
                }

                TextView v = (TextView) holder.findViewById(R.id.detailed_item_list_item_text1);
                v.setText(group.m_info.m_fio);
                v = (TextView) holder.findViewById(R.id.detailed_item_list_item_text2);
                v.setText("");
                v = (TextView) holder.findViewById(R.id.detailed_item_list_item_text3);
                v.setText(group.m_info.m_chair);
                return holder;
              }
            };
        list.setAdapter(recent_adapter);
        // ListView Item Click Listener
        list.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {

              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Lecturer lect = (Lecturer) recent_adapter.getItem(position);

                Log.d("init", lect.toString());
                if (((NavigationView) getActivity().findViewById(R.id.nav_view))
                    .getMenu()
                    .getItem(0)
                    .isChecked()) {
                  ((MainNavigationDrawer) getActivity()).createTree(lect);
                  //                            new CreateFiles(getActivity(), lect).execute();
                } else {
                  ((MainNavigationDrawer) getActivity())
                      .switchContent(TimeTableFragment.newInstance(lect));
                  StaticStorage.m_recentLecturers.put(lect.m_info.m_id, lect);
                }
              }
            });
        /*
        Button btn = (Button) view.findViewById(R.id.primat_list);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(getResources().getString(R.string.str_depth));

                ListView modeList = new ListView(getActivity());
                ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(getActivity(),
                        android.R.help.simple_list_item_1, android.R.id.text1,
                        StaticStorage.m_primatLecturerName);
                modeList.setAdapter(modeAdapter);

                builder.setView(modeList);
                final Dialog dialog = builder.create();

                dialog.show();
            }
        });
        */
        Button btn = (Button) view.findViewById(R.id.primat_list);
        btn.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (!((MainNavigationDrawer) getActivity()).isOnline())
                  ((MainNavigationDrawer) getActivity()).askForInternet();
                else new ServerGetPrimatLecturers(getActivity(), true).execute();
              }
            });
      }
    }

    //
    // ((CollapsingToolbarLayout)getActivity().findViewById(R.id.collapsing_toolbar_layout)).setTitle(getResources().getString(R.string.search));
    //
    // ((Toolbar)getActivity().findViewById(R.id.toolbar)).setTitle(getResources().getString(R.string.search));

    if (((NavigationView) getActivity().findViewById(R.id.nav_view))
        .getMenu()
        .getItem(0)
        .isChecked()) {
      if (mType == t_type.GROUP) {
        ((AppCompatActivity) getActivity())
            .getSupportActionBar()
            .setTitle(getResources().getString(R.string.choose_group));
      } else {
        ((AppCompatActivity) getActivity())
            .getSupportActionBar()
            .setTitle(getResources().getString(R.string.choose_lectname));
      }
    } else {
      ((AppCompatActivity) getActivity())
          .getSupportActionBar()
          .setTitle(getResources().getString(R.string.search));
    }

    return view;
  }