Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- call = tagApi.getTasks(tags);
- call.enqueue(new Callback<Api>()
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //hide toolbar
- /*Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);*/
- ButterKnife.bind(this);
- listTags = new ArrayList<>();
- listTagsFinal = new ArrayList<>();
- listTagsRest = new ArrayList<>();
- strings = new ArrayList<>();
- //search text handler
- svSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
- @Override
- public boolean onQueryTextSubmit(String query) {
- result = query.split(",?\ ");
- //numberTag = result.length;
- for (int i = 0; i < result.length; i++) {
- ApiHit(result[i]);
- }
- FinalSort();
- return true;
- }
- @Override
- public boolean onQueryTextChange(String newText) {
- //This is your adapter that will be filtered
- return false;
- }
- });
- }
- public void ApiHit(final String tags) {
- //retrofit
- TagApi tagApi = NetworkService.retrofit.create(TagApi.class);
- Call<Api> call;
- //recieve words from searchview, divide and put into string array
- call = tagApi.getTasks(tags);
- call.enqueue(new Callback<Api>() {
- @Override
- public void onResponse(Call<Api> call, Response<Api> response) {
- //recieve possible tags for one word and put it into list
- for (int i = 0; i < response.body().getResults().size(); i++) {
- listTags.add(new RowModel(response.body().getResults().get(i).getTag(), response.body().getResults().get(i).getAbsRelevance()));
- }
- //sort whole list
- Collections.sort(listTags);
- //add first tags to list
- if (listTags.size()>0) {
- for (int y = 0; y < 3 && y < listTags.size() ; y++) {
- listTagsFinal.add(new RowModel(listTags.get(y).getName(), listTags.get(y).getPosition()));
- }
- }
- if (!isTagognizerTag) {
- listTagsFinal.add(new RowModel("tagognizer", 0.0022055893));
- isTagognizerTag = true;
- }
- //add rest tags to list
- for (int y = 3; y < listTags.size(); y++) {
- listTagsRest.add(new RowModel(listTags.get(y).getName(), listTags.get(y).getPosition()));
- }
- //create final array when response reach last tag
- /* if (checker == tags.length) {
- //final sort
- FinalSort();
- }*/
- listTags.clear();
- checker++;
- }
- @Override
- public void onFailure(Call<Api> call, Throwable t) {
- }
- });
- }
Add Comment
Please, Sign In to add comment