|
1 | 1 | package com.carboni.cinebuff;
|
2 | 2 |
|
3 | 3 | import android.os.Bundle;
|
4 |
| -import android.support.design.widget.FloatingActionButton; |
5 | 4 | import android.support.v7.app.AppCompatActivity;
|
6 | 5 | import android.support.v7.widget.Toolbar;
|
7 |
| -import android.text.Editable; |
8 |
| -import android.text.TextWatcher; |
9 |
| -import android.util.Log; |
10 | 6 | import android.view.View;
|
11 | 7 | import android.view.Menu;
|
12 | 8 | import android.view.MenuItem;
|
13 | 9 | import android.widget.AdapterView;
|
14 |
| -import android.widget.EditText; |
15 |
| -import android.widget.Toast; |
16 | 10 |
|
17 | 11 | import com.carboni.cinebuff.adapter.AutoCompleteAdapter;
|
18 |
| -import com.carboni.cinebuff.model.Person; |
19 | 12 | import com.carboni.cinebuff.model.Result;
|
20 |
| -import com.carboni.cinebuff.presenter.PersonPresenter; |
21 |
| -import com.carboni.cinebuff.view.PersonView; |
22 | 13 |
|
23 | 14 | import butterknife.BindView;
|
24 | 15 | import butterknife.ButterKnife;
|
25 |
| -import butterknife.OnClick; |
26 |
| -import retrofit2.Call; |
27 |
| -import retrofit2.Response; |
28 | 16 |
|
29 |
| -public class MainActivity extends AppCompatActivity implements PersonView { |
| 17 | +public class MainActivity extends AppCompatActivity { |
30 | 18 | @BindView(R.id.toolbar)
|
31 | 19 | Toolbar toolbar;
|
32 |
| - @BindView(R.id.fab) |
33 |
| - FloatingActionButton fab; |
34 |
| - @BindView(R.id.editTextPersonQuery) |
35 |
| - EditText editTextQuery; |
36 | 20 | @BindView(R.id.personAutoComplete)
|
37 | 21 | DelayAutoCompleteTextView searchView;
|
38 | 22 |
|
39 |
| - PersonPresenter presenter; |
40 |
| - |
41 | 23 | @Override
|
42 | 24 | protected void onCreate(Bundle savedInstanceState) {
|
43 | 25 | super.onCreate(savedInstanceState);
|
44 | 26 | setContentView(R.layout.activity_main);
|
45 | 27 | ButterKnife.bind(this);
|
46 | 28 |
|
47 |
| - // Giving our PersonPresenter a reference to the View |
48 |
| - presenter = new PersonPresenter(this); |
49 |
| - |
50 | 29 | setSupportActionBar(toolbar);
|
51 | 30 |
|
52 |
| - fab.setVisibility(View.INVISIBLE); |
53 |
| - editTextQuery.addTextChangedListener(new TextWatcher() { |
54 |
| - @Override |
55 |
| - public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
56 |
| - } |
57 |
| - |
58 |
| - @Override |
59 |
| - public void onTextChanged(CharSequence s, int start, int before, int count) { |
60 |
| - if (s.length() > 0) { |
61 |
| - fab.show(); |
62 |
| - } else if (s.length() == 0) { |
63 |
| - fab.hide(); |
64 |
| - } |
65 |
| - } |
66 |
| - |
67 |
| - @Override |
68 |
| - public void afterTextChanged(Editable s) { |
69 |
| - |
70 |
| - } |
71 |
| - }); |
72 |
| - |
73 | 31 | searchView.setThreshold(3); // min number of characters before dropdown is shown
|
74 | 32 | searchView.setAdapter(new AutoCompleteAdapter(this));
|
75 | 33 | searchView.setLoadingIndicator((android.widget.ProgressBar) findViewById(R.id.loading_indicator));
|
76 | 34 | searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
77 | 35 | @Override
|
78 | 36 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
79 | 37 | Result result = (Result) parent.getItemAtPosition(position);
|
80 |
| - Toast.makeText(getApplicationContext(), "Pressed " + result.getName() + " " + result.getId(), Toast.LENGTH_SHORT).show(); |
81 | 38 | }
|
82 | 39 | });
|
83 | 40 | }
|
84 | 41 |
|
85 |
| - /* |
86 |
| - Gather user input and pass to the presenter |
87 |
| - */ |
88 |
| - @OnClick(R.id.fab) |
89 |
| - void onFabClick() { |
90 |
| - String query = editTextQuery.getText().toString(); |
91 |
| - presenter.attemptSearch(query); |
92 |
| - Log.i("MainActivity", "Presenter called to attempt search"); |
93 |
| - } |
94 |
| - |
95 |
| - @Override |
96 |
| - public void showSuccess(Call<Person> list, Response<Person> response) { |
97 |
| - Log.i("MainActivity", "Success"); |
98 |
| - } |
99 |
| - |
100 |
| - @Override |
101 |
| - public void showFailure(Throwable error) { |
102 |
| - Log.i("MainActivity", "Failure from Presenter: " + error.getMessage().toString()); |
103 |
| - } |
104 |
| - |
105 | 42 | @Override
|
106 | 43 | public boolean onCreateOptionsMenu(Menu menu) {
|
107 | 44 | // Inflate the menu; this adds items to the action bar if it is present.
|
|
0 commit comments