private void searchTwitter() { if (search != null && search.length() > 2) { if (searchTwitterTask != null) { searchTwitterTask.cancel(true); searchTwitterTask = null; } searchTwitter_v.setVisibility(twitter.hasAccessToken() ? View.GONE : View.VISIBLE); searchDiv_v.setVisibility(twitter.hasAccessToken() ? View.GONE : View.VISIBLE); searchTwitterTask = new SearchTwitterTask(); searchTwitterTask.execute(); } else { twitterFeedSearch.clear(); searchAdapter.notifyDataSetChanged(); } }
@Override public void onClick(View v) { Log.d(TAG, "onclick " + (v == action_fab) + ", " + searchMode); if (v == search_fab) { if (searchMode == Var.SEARCH_NONE) toggleSearch(Var.SEARCH_OPTIONS); else if (searchMode == Var.SEARCH_OPTIONS) toggleSearch(Var.SEARCH_NONE); } if (v == action_fab) { if (searchMode == Var.SEARCH_YT_CHANNEL) { SparseBooleanArray checked = search_lv.getCheckedItemPositions(); for (int i = 0; i < checked.size(); i++) { if (checked.valueAt(i) == true) { YoutubeFeed youtubeFeed = (YoutubeFeed) search_lv.getItemAtPosition(checked.keyAt(i)); youtubeFeed.setChannelHandle(searchChannel.getFeedId()); editUser.getMediaFeed().add(youtubeFeed); } } feedAdapter.notifyDataSetChanged(); clearSearchOptions(); toggleSearch(Var.SEARCH_NONE); } else if (searchMode == Var.SEARCH_NONE) { editUser.setName(userName_edt.getText().toString().trim()); editUser.setNotification(notification_sw.isChecked()); editUser.setThumbnail((String) userPicture_sp.getSelectedItem()); UserORM.saveUser(this, editUser); finish(); } } if (v == youtube_ll) toggleSearch(Var.SEARCH_YOUTUBE); if (v == twitter_ll) toggleSearch(Var.SEARCH_TWITTER); if (v == search_v) toggleSearch(Var.SEARCH_NONE); if (v == searchTwitterLogin_tv) { twitter.resetAccessToken(); if (!twitter.hasAccessToken()) twitter.authorize(); // Hide the signin searchTwitter_v.setVisibility(View.GONE); searchDiv_v.setVisibility(View.GONE); } if (v == clearSearch_iv) search_edt.getText().clear(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); imageLoader = new ImageLoader(this); editUser = new User(); youtubeChannelSearch = new ArrayList<YoutubeChannel>(); twitterFeedSearch = new ArrayList<TwitterFeed>(); userPictureThumbnails = new ArrayList<String>(); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); groups = GroupORM.getVisibleGroups(this); View header = getLayoutInflater().inflate(R.layout.header_add, null, false); View searchHeader = getLayoutInflater().inflate(R.layout.header_search_user, null, false); feed_lv = (ListView) findViewById(R.id.feed_lv); feed_lv.addHeaderView(header, null, false); feedAdapter = new FeedAdapter(this); feed_lv.setAdapter(feedAdapter); // Header userPicture_sp = (Spinner) header.findViewById(R.id.user_picture_sp); userName_edt = (EditText) header.findViewById(R.id.user_name_edt); group_sp = (SpinnerTrigger) header.findViewById(R.id.group_sp); notification_sw = (SwitchCompat) header.findViewById(R.id.notification_sw); search_fab = (Fab) header.findViewById(R.id.search_fab); youtube_fab = (Fab) header.findViewById(R.id.youtube_fab); twitter_fab = (Fab) header.findViewById(R.id.twitter_fab); youtube_ll = (LinearLayout) header.findViewById(R.id.youtube_ll); twitter_ll = (LinearLayout) header.findViewById(R.id.twitter_ll); groupAdapter = new GroupAdapter(this, groups); group_sp.setAdapter(groupAdapter); group_sp.setOnItemSelectedListener(this); // Search search_rl = findViewById(R.id.search_rl); search_edt = (EditText) findViewById(R.id.search_edt); search_edt.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { pageToken = null; twitterPage = 0; search = s.toString(); searchMessage_tv.setVisibility(View.GONE); searchTimer(); } }); clearSearch_iv = (ImageView) findViewById(R.id.clear_iv); clearSearch_iv.setOnClickListener(this); /*searchView = (SearchView) findViewById(R.id.action_search); //MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(this); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { toggleSearch(Var.SEARCH_NONE); return false; } });*/ search_v = findViewById(R.id.search_v); search_v.setOnClickListener(this); channel_v = searchHeader.findViewById(R.id.channel_v); thumbnail_iv = (ImageView) channel_v.findViewById(R.id.thumbnail_iv); name_tv = (TextView) channel_v.findViewById(R.id.name_tv); searchTwitter_v = searchHeader.findViewById(R.id.twitter_v); searchDiv_v = searchHeader.findViewById(R.id.div_v); searchMessage_tv = (TextView) searchHeader.findViewById(R.id.search_message_tv); searchTwitterLogin_tv = (TextView) searchHeader.findViewById(R.id.twitter_login_tv); searchTwitterLogin_tv.setOnClickListener(this); search_lv = (ListView) findViewById(R.id.search_lv); search_lv.addHeaderView(searchHeader, null, false); searchAdapter = new SearchAdapter(this); search_lv.setAdapter(searchAdapter); search_lv.setOnScrollListener(this); search_lv.setOnItemClickListener(this); iconAdapter = new IconAdapter(this, userPictureThumbnails, imageLoader); userPicture_sp.setAdapter(iconAdapter); // userPicture_sp.setOnItemSelectedListener(this); action_fab = (Fab) findViewById(R.id.action_fab); action_fab.setOnClickListener(this); search_fab.setOnClickListener(this); youtube_ll.setOnClickListener(this); twitter_ll.setOnClickListener(this); // youtube_ll.setOnTouchListener(this); // twitter_ll.setOnTouchListener(this); twitter = new TwitterUtil(this); twitter.setListener( new Listener() { @Override public void onError(String value) { Toast.makeText(AddActivity.this, "Login Failed", Toast.LENGTH_LONG).show(); Log.e("TWITTER", value); twitter.resetAccessToken(); } @Override public void onComplete(String value) { Log.d(TAG, "twitter listener authorized " + twitter.getUsername()); } }); spinnerInit = 1; // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // getSupportActionBar().setTitle("Add User"); toggleSearch(Var.SEARCH_NONE); }
private void toggleSearch(int searchMode) { this.searchMode = searchMode; search_v.setVisibility(searchModePreSearch() ? View.GONE : View.VISIBLE); searchTwitter_v.setVisibility( (searchMode == Var.SEARCH_TWITTER && !twitter.hasAccessToken()) ? View.VISIBLE : View.GONE); searchDiv_v.setVisibility( (searchMode == Var.SEARCH_TWITTER && twitter.hasAccessToken()) ? View.GONE : View.VISIBLE); youtube_ll.setVisibility((searchMode == Var.SEARCH_OPTIONS) ? View.VISIBLE : View.GONE); twitter_ll.setVisibility((searchMode == Var.SEARCH_OPTIONS) ? View.VISIBLE : View.GONE); channel_v.setVisibility((searchMode == Var.SEARCH_YT_CHANNEL) ? View.VISIBLE : View.GONE); search_fab.setVisibility( (searchModePreSearch() || searchMode == Var.SEARCH_YT_CHANNEL) ? View.VISIBLE : View.GONE); search_fab.setDrawable( getResources() .getDrawable( searchMode == Var.SEARCH_YT_CHANNEL ? R.drawable.ic_add_white_18dp : R.drawable.ic_search_white_24dp)); search_lv.setChoiceMode( (searchMode == Var.SEARCH_YT_CHANNEL) ? ListView.CHOICE_MODE_MULTIPLE : ListView.CHOICE_MODE_SINGLE); if (searchMode == Var.SEARCH_NONE) { dismissSearch(); // searchView.setQuery("", false); // searchView.setVisibility(View.GONE); search_rl.setVisibility(View.GONE); search_edt.getText().clear(); action_fab.setVisibility((editUser.getMediaFeed().size() > 0) ? View.VISIBLE : View.GONE); search_lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); youtubeChannelSearch.clear(); twitterFeedSearch.clear(); searchAdapter.notifyDataSetChanged(); } if (searchMode == Var.SEARCH_YT_CHANNEL) { dismissSearch(); action_fab.setVisibility(View.VISIBLE); search_lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); clearSearchOptions(); } else if (searchMode == Var.SEARCH_YOUTUBE || searchMode == Var.SEARCH_TWITTER) { // if(searchItem != null) { // searchView.setQueryHint(getResources().getString((searchMode == Var.SEARCH_YOUTUBE) ? // R.string.search_youtube : R.string.search_twitter)); // searchView.setIconified(false); // searchView.setVisibility(View.VISIBLE); // searchView.requestFocusFromTouch(); search_edt.setHint( (searchMode == Var.SEARCH_YOUTUBE) ? R.string.search_youtube : R.string.search_twitter); search_rl.setVisibility(View.VISIBLE); search_rl.requestFocus(); // } } if (searchModePreSearch()) { search_fab.setDrawable( getResources() .getDrawable( searchMode == Var.SEARCH_NONE ? R.drawable.ic_search_white_24dp : R.drawable.ic_close_white_36dp)); } }