Have started building views. Still need to populate them with data. The application boots now at least.
This commit is contained in:
parent
9614ae2020
commit
0846b90952
|
@ -77,6 +77,5 @@ public class ApplicationTest extends AndroidTestCase {
|
|||
Cursor cursor = getContext().getContentResolver()
|
||||
.query(EventContract.EventEntry.CONTENT_URI, null, null, null, null);
|
||||
assertNotNull(cursor);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package no.nilsnh.uibevents;
|
||||
|
||||
public class DetailActivity {
|
||||
}
|
49
app/src/main/java/no/nilsnh/uibevents/EventAdapter.java
Normal file
49
app/src/main/java/no/nilsnh/uibevents/EventAdapter.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
package no.nilsnh.uibevents;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import no.nilsnh.uibevents.data.EventContract;
|
||||
|
||||
public class EventAdapter extends CursorAdapter {
|
||||
|
||||
public static class ViewHolder {
|
||||
public final TextView dateFromView;
|
||||
public final TextView dateToView;
|
||||
public final TextView titleView;
|
||||
public final TextView categoryView;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
dateFromView = (TextView) view.findViewById(R.id.list_item_date_from_textview);
|
||||
dateToView = (TextView) view.findViewById(R.id.list_item_date_to_textview);
|
||||
titleView = (TextView) view.findViewById(R.id.list_item_title_textview);
|
||||
categoryView = (TextView) view.findViewById(R.id.list_item_category_textview);
|
||||
}
|
||||
}
|
||||
|
||||
public EventAdapter(Context context, Cursor c, int flags) {
|
||||
super(context, c, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.list_item_event, parent, false);
|
||||
ViewHolder viewHolder = new ViewHolder(view);
|
||||
view.setTag(viewHolder);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
||||
viewHolder.titleView.setText(cursor.getString(EventFragment.COL_EVENT_TITLE));
|
||||
viewHolder.dateFromView.setText(cursor.getString(EventFragment.COL_EVENT_DATE_FROM));
|
||||
viewHolder.dateToView.setText(cursor.getString(EventFragment.COL_EVENT_DATE_TO));
|
||||
viewHolder.categoryView.setText(cursor.getString(EventFragment.COL_EVENT_TYPE));
|
||||
}
|
||||
}
|
126
app/src/main/java/no/nilsnh/uibevents/EventFragment.java
Normal file
126
app/src/main/java/no/nilsnh/uibevents/EventFragment.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
package no.nilsnh.uibevents;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import no.nilsnh.uibevents.data.Event;
|
||||
import no.nilsnh.uibevents.data.EventContract;
|
||||
|
||||
public class EventFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
public static final String LOG_TAG = EventFragment.class.getSimpleName();
|
||||
private EventAdapter eventAdapter;
|
||||
private ListView mListView;
|
||||
private int mPosition = ListView.INVALID_POSITION;
|
||||
|
||||
private static final String SELECTED_KEY = "selected_position";
|
||||
|
||||
static final int COL_EVENT_ID = 0;
|
||||
static final int COL_EVENT_TYPE = 1;
|
||||
static final int COL_EVENT_TITLE = 2;
|
||||
static final int COL_EVENT_DATE_FROM = 3;
|
||||
static final int COL_EVENT_DATE_TO = 4;
|
||||
static final int COL_EVENT_LOCATION = 5;
|
||||
static final int COL_EVENT_DETAILS = 6;
|
||||
static final int COL_EVENT_URL = 7;
|
||||
|
||||
public EventFragment() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Add this line in order for this fragment to handle menu events.
|
||||
// setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
eventAdapter = new EventAdapter(getActivity(), null, 0);
|
||||
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
|
||||
|
||||
// Get a reference to the ListView, and attach this adapter to it.
|
||||
mListView = (ListView) rootView.findViewById(R.id.listview_event);
|
||||
mListView.setAdapter(eventAdapter);
|
||||
// We'll call our MainActivity
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
||||
// CursorAdapter returns a cursor at the correct position for getItem(), or null
|
||||
// if it cannot seek to that position.
|
||||
Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
|
||||
if (cursor != null) {
|
||||
//kicks off callback containing uri
|
||||
((Callback) getActivity())
|
||||
.onItemSelected(EventContract.EventEntry.buildEventUri(
|
||||
cursor.getLong(COL_EVENT_ID)
|
||||
));
|
||||
}
|
||||
mPosition = position;
|
||||
}
|
||||
});
|
||||
|
||||
// If there's instance state, mine it for useful information.
|
||||
// The end-goal here is that the user never knows that turning their device sideways
|
||||
// does crazy lifecycle related things. It should feel like some stuff stretched out,
|
||||
// or magically appeared to take advantage of room, but data or place in the app was never
|
||||
// actually *lost*.
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
|
||||
// The listview probably hasn't even been populated yet. Actually perform the
|
||||
// swapout in onLoadFinished.
|
||||
mPosition = savedInstanceState.getInt(SELECTED_KEY);
|
||||
}
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
return new CursorLoader(getActivity(),
|
||||
EventContract.EventEntry.CONTENT_URI,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||
eventAdapter.swapCursor(data);
|
||||
if (mPosition != ListView.INVALID_POSITION) {
|
||||
// If we don't need to restart the loader, and there's a desired position to restore
|
||||
// to, do so now.
|
||||
mListView.smoothScrollToPosition(mPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
eventAdapter.swapCursor(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback interface that all activities containing this fragment must
|
||||
* implement. This mechanism allows activities to be notified of item
|
||||
* selections.
|
||||
*/
|
||||
public interface Callback {
|
||||
/**
|
||||
* DetailFragmentCallback for when an item has been selected.
|
||||
*/
|
||||
public void onItemSelected(Uri dateUri);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package no.nilsnh.uibevents;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
|
@ -10,12 +12,40 @@ import android.view.MenuItem;
|
|||
import no.nilsnh.uibevents.data.EventDbHelper;
|
||||
|
||||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
public class MainActivity extends ActionBarActivity implements EventFragment.Callback {
|
||||
|
||||
private final String LOG_TAG = MainActivity.class.getSimpleName();
|
||||
private static final String DETAILFRAGMENT_TAG = "DFTAG";
|
||||
|
||||
private boolean mTwoPane;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// setContentView(R.layout.activity_main);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
// if (findViewById(R.id.weather_detail_container) != null) {
|
||||
// // The detail container view will be present only in the large-screen layouts
|
||||
// // (res/layout-sw600dp). If this view is present, then the activity should be
|
||||
// // in two-pane mode.
|
||||
// mTwoPane = true;
|
||||
// // In two-pane mode, show the detail view in this activity by
|
||||
// // adding or replacing the detail fragment using a
|
||||
// // fragment transaction.
|
||||
// if (savedInstanceState == null) {
|
||||
// getSupportFragmentManager().beginTransaction()
|
||||
// .replace(R.id.weather_detail_container, new DetailFragment(), DETAILFRAGMENT_TAG)
|
||||
// .commit();
|
||||
// }
|
||||
// } else {
|
||||
mTwoPane = false;
|
||||
getSupportActionBar().setElevation(0f);
|
||||
|
||||
// EventFragment eventFragment = ((EventFragment)getSupportFragmentManager()
|
||||
// .findFragmentById(R.id.fragment_forecast));
|
||||
// eventFragment.setUseTodayLayout(!mTwoPane);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,4 +69,25 @@ public class MainActivity extends ActionBarActivity {
|
|||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(Uri contentUri) {
|
||||
// if (mTwoPane) {
|
||||
// // In two-pane mode, show the detail view in this activity by
|
||||
// // adding or replacing the detail fragment using a
|
||||
// // fragment transaction.
|
||||
// Bundle args = new Bundle();
|
||||
// args.putParcelable(DetailFragment.DETAIL_URI, contentUri);
|
||||
//
|
||||
// DetailFragment fragment = new DetailFragment();
|
||||
// fragment.setArguments(args);
|
||||
//
|
||||
// getSupportFragmentManager().beginTransaction()
|
||||
// .replace(R.id.weather_detail_container, fragment, DETAILFRAGMENT_TAG)
|
||||
// .commit();
|
||||
// } else {
|
||||
Intent intent = new Intent(this, DetailActivity.class)
|
||||
.setData(contentUri);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,7 +175,6 @@ public class EventDbHelper {
|
|||
|
||||
public int delete(String tableName, String selection, String[] selectionArgs) {
|
||||
ArrayList<Event> storedEvents = getStoredData();
|
||||
ArrayList<Event> entriesToDelete = new ArrayList<>();
|
||||
Integer numDeletedRows = null;
|
||||
|
||||
//If everything is to be deleted just delete the file
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.ContentValues;
|
|||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
|
||||
public class EventProvider extends ContentProvider {
|
||||
|
@ -87,7 +88,21 @@ public class EventProvider extends ContentProvider {
|
|||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
return 0;
|
||||
final int match = sUriMatcher.match(uri);
|
||||
int rowsUpdated;
|
||||
switch (match) {
|
||||
case EVENT:
|
||||
rowsUpdated = eventDbHelper.delete(
|
||||
EventContract.EventEntry.TABLE_NAME, selection, selectionArgs);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
}
|
||||
// Because a null deletes all rows
|
||||
if (rowsUpdated != 0) {
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
}
|
||||
return rowsUpdated;
|
||||
}
|
||||
|
||||
static UriMatcher buildUriMatcher() {
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
|
||||
|
||||
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</RelativeLayout>
|
||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/fragment_event"
|
||||
android:name="no.nilsnh.uibevents.EventFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="no.nilsnh.uibevents.EventFragment"
|
||||
tools:layout="@android:layout/list_content" />
|
12
app/src/main/res/layout/fragment_main.xml
Normal file
12
app/src/main/res/layout/fragment_main.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.example.android.sunshine.app.ForecastFragment">
|
||||
<ListView
|
||||
style="@style/EventListStyle"
|
||||
android:id="@+id/listview_event"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:divider="@null" />
|
||||
</FrameLayout>
|
48
app/src/main/res/layout/list_item_event.xml
Normal file
48
app/src/main/res/layout/list_item_event.xml
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/list_item_title_textview"
|
||||
android:id="@+id/list_item_title_textview"
|
||||
android:padding="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/list_item_category_textview"
|
||||
android:id="@+id/list_item_category_textview"
|
||||
android:padding="10dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/list_item_date_from_textview"
|
||||
android:id="@+id/list_item_date_from_textview"
|
||||
android:padding="10dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/list_item_date_to_textview"
|
||||
android:id="@+id/list_item_date_to_textview"
|
||||
android:padding="10dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -4,4 +4,8 @@
|
|||
<string name="hello_world">Hello world!</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="content_authority">no.nilsnh.uibevents</string>
|
||||
<string name="list_item_category_textview">exhibition</string>
|
||||
<string name="list_item_date_from_textview">18.11.15</string>
|
||||
<string name="list_item_date_to_textview">20.11.15</string>
|
||||
<string name="list_item_title_textview">The Norwegian Constitution \"VI: 1814 - 2014\"</string>
|
||||
</resources>
|
||||
|
|
|
@ -5,4 +5,6 @@
|
|||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
<style name="EventListStyle"></style>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue