Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package twitterapp.hummingbird.nl.hummingbird;
- import android.app.AlertDialog;
- import android.app.Dialog;
- import android.app.SearchManager;
- import android.content.Context;
- import android.content.Intent;
- import android.support.v4.app.DialogFragment;
- import android.support.v4.widget.SwipeRefreshLayout;
- import android.support.v7.app.ActionBarActivity;
- import android.os.Bundle;
- import android.support.v7.widget.SearchView;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.Button;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.melnykov.fab.FloatingActionButton;
- import com.sothree.slidinguppanel.SlidingUpPanelLayout;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.Observable;
- import java.util.Observer;
- import twitterapp.hummingbird.nl.hummingbird.model.Model;
- import twitterapp.hummingbird.nl.hummingbird.model.Tweet;
- import twitterapp.hummingbird.nl.hummingbird.view.TweetListAdapter;
- public class MainActivity extends ActionBarActivity implements Observer {
- HummingbirdApplication app;
- Model model;
- TweetListAdapter tweetListAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- app = (HummingbirdApplication) getApplicationContext();
- model = app.getModel();
- try {
- JSONObject json = new JSONObject(app.getJsonText());
- model.addTweets(json);
- } catch (JSONException e) {
- //ToDo: Error netjes afhandelen
- e.printStackTrace();
- }
- tweetListAdapter = new TweetListAdapter(this,R.layout.tweet_list_item, model.getTweets());
- ListView tweetsList = (ListView) findViewById(R.id.lvTweetsOverview);
- tweetsList.setAdapter(tweetListAdapter);
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.attachToListView(tweetsList);
- // Handle clicking on fab
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Toast.makeText(app, "TODO: Toon Tweet maken dialog.", Toast.LENGTH_SHORT).show();
- }
- });
- // Handle clicking on tweets
- tweetsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
- Intent intent = new Intent(app, TweetDetailActivity.class);
- intent.putExtra("tweetIndex", i);
- startActivity(intent);
- }
- });
- // Handle swipe to refresh
- final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh);
- swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- Toast.makeText(app, "TODO: Refreshen van tweets.", Toast.LENGTH_SHORT).show();
- if (swipeLayout.isRefreshing()) {
- swipeLayout.setRefreshing(false);
- }
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_main, menu);
- SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
- searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
- @Override
- public boolean onQueryTextSubmit(String s) {
- Log.d("searchtest", "onQueryTextSubmit ");
- return false;
- }
- @Override
- public boolean onQueryTextChange(String s) {
- Log.d("searchtest", "onQueryTextChange ");
- return false;
- }
- });
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- // if (id == R.id.action_settings) {
- // return true;
- // }
- return super.onOptionsItemSelected(item);
- }
- /**
- * This method is called if the specified {@code Observable} object's
- * {@code notifyObservers} method is called (because the {@code Observable}
- * object has been updated.
- *
- * @param observable the {@link Observable} object.
- * @param data the data passed to {@link Observable#notifyObservers(Object)}.
- */
- @Override
- public void update(Observable observable, Object data) {
- tweetListAdapter.notifyDataSetChanged();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement