almost there. Is able to view detail layout
This commit is contained in:
parent
85d6ed5983
commit
d729489c50
|
@ -24,6 +24,14 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".DetailActivity"
|
||||
android:label="@string/title_activity_detail"
|
||||
android:parentActivityName=".MainActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="no.nilsnh.uibevents.MainActivity" />
|
||||
</activity>
|
||||
<provider
|
||||
android:authorities="@string/content_authority"
|
||||
android:name=".data.EventProvider"
|
||||
|
|
|
@ -1,4 +1,41 @@
|
|||
package no.nilsnh.uibevents;
|
||||
|
||||
public class DetailActivity {
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class DetailActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_detail);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
// Create the detail fragment and add it to the activity
|
||||
// using a fragment transaction.
|
||||
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelable(DetailFragment.DETAIL_URI, getIntent().getData());
|
||||
|
||||
DetailFragment fragment = new DetailFragment();
|
||||
fragment.setArguments(arguments);
|
||||
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.event_detail_container, fragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
128
app/src/main/java/no/nilsnh/uibevents/DetailFragment.java
Normal file
128
app/src/main/java/no/nilsnh/uibevents/DetailFragment.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package no.nilsnh.uibevents;
|
||||
|
||||
import android.content.Intent;
|
||||
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.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.widget.ShareActionProvider;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public class DetailFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
|
||||
private static final String LOG_TAG = DetailFragment.class.getSimpleName();
|
||||
static final String DETAIL_URI = "URI";
|
||||
private Uri mUri;
|
||||
private static final int DETAIL_LOADER = 0;
|
||||
|
||||
static final int COL_EVENT_ID = 0;
|
||||
static final int COL_EVENT_API_ID = 1;
|
||||
static final int COL_EVENT_TYPE = 2;
|
||||
static final int COL_EVENT_TITLE = 3;
|
||||
static final int COL_EVENT_DATE_FROM = 4;
|
||||
static final int COL_EVENT_DATE_TO = 5;
|
||||
static final int COL_EVENT_LOCATION = 6;
|
||||
static final int COL_EVENT_DETAILS = 7;
|
||||
static final int COL_EVENT_URL = 8;
|
||||
|
||||
|
||||
private TextView titleView;
|
||||
private TextView categoryView;
|
||||
private TextView detailView;
|
||||
private TextView dateFromView;
|
||||
private TextView dateToView;
|
||||
|
||||
public DetailFragment() {
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
Bundle arguments = getArguments();
|
||||
if (arguments != null) {
|
||||
mUri = arguments.getParcelable(DetailFragment.DETAIL_URI);
|
||||
}
|
||||
View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
|
||||
titleView = (TextView) rootView.findViewById(R.id.list_item_title_textview);
|
||||
categoryView = (TextView) rootView.findViewById(R.id.list_item_category_textview);
|
||||
detailView = (TextView) rootView.findViewById(R.id.list_item_details_textview);
|
||||
dateFromView = (TextView) rootView.findViewById(R.id.list_item_date_from_textview);
|
||||
dateToView = (TextView) rootView.findViewById(R.id.list_item_date_to_textview);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
getLoaderManager().initLoader(DETAIL_LOADER, null, this);
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
if ( null != mUri ) {
|
||||
// Now create and return a CursorLoader that will take care of
|
||||
// creating a Cursor for the data being displayed.
|
||||
return new CursorLoader(
|
||||
getActivity(),
|
||||
mUri,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||
if (data != null && data.moveToFirst()) {
|
||||
titleView.setText(data.getString(COL_EVENT_TITLE));
|
||||
categoryView.setText(data.getString(COL_EVENT_TYPE));
|
||||
detailView.setText(data.getString(COL_EVENT_DETAILS));
|
||||
dateFromView.setText(data.getString(COL_EVENT_DATE_FROM));
|
||||
dateToView.setText(data.getString(COL_EVENT_DATE_TO));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) { }
|
||||
}
|
|
@ -67,7 +67,7 @@ public class EventFragment extends Fragment implements LoaderManager.LoaderCallb
|
|||
//kicks off callback containing uri
|
||||
((Callback) getActivity())
|
||||
.onItemSelected(EventContract.EventEntry.buildEventUri(
|
||||
cursor.getLong(COL_EVENT_ID)
|
||||
cursor.getLong(COL_EVENT_API_ID)
|
||||
));
|
||||
}
|
||||
mPosition = position;
|
||||
|
|
|
@ -3,6 +3,7 @@ package no.nilsnh.uibevents.data;
|
|||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -230,10 +231,7 @@ public class EventDbHelper {
|
|||
public MatrixCursor query() {
|
||||
ArrayList<Event> storedEvents = getStoredData();
|
||||
MatrixCursor mCursor = new MatrixCursor(Event.getKeysAsStringList());
|
||||
|
||||
String[] values = new String[]{"1"};
|
||||
|
||||
Event event = null;
|
||||
Event event;
|
||||
for (int i = 0; i < storedEvents.size() -1; i++) {
|
||||
event = storedEvents.get(i);
|
||||
mCursor.addRow(new String[]{
|
||||
|
@ -250,4 +248,32 @@ public class EventDbHelper {
|
|||
}
|
||||
return mCursor;
|
||||
}
|
||||
|
||||
public MatrixCursor query(Uri uri) {
|
||||
ArrayList<Event> storedEvents = getStoredData();
|
||||
MatrixCursor mCursor = new MatrixCursor(Event.getKeysAsStringList());
|
||||
Event event;
|
||||
String[] values;
|
||||
for (int i = 0; i < storedEvents.size() -1; i++) {
|
||||
event = storedEvents.get(i);
|
||||
values = new String[]{
|
||||
String.valueOf(i + 1),
|
||||
event.getId(),
|
||||
event.getType(),
|
||||
event.getTitle(),
|
||||
event.getDateFrom(),
|
||||
event.getDateTo(),
|
||||
event.getLocation(),
|
||||
event.getDetails(),
|
||||
event.getUrl()
|
||||
};
|
||||
if (event.getId().equals(uri.getLastPathSegment()))
|
||||
mCursor.addRow(values);
|
||||
}
|
||||
return mCursor;
|
||||
}
|
||||
|
||||
public String getEventIdFromUri(Uri uri){
|
||||
return uri.getLastPathSegment();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EventProvider extends ContentProvider {
|
|||
private EventDbHelper eventDbHelper;
|
||||
private static final UriMatcher sUriMatcher = buildUriMatcher();
|
||||
static final int EVENT = 100;
|
||||
static final int EVENT_WITH_ID = 101;
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
|
@ -29,6 +30,10 @@ public class EventProvider extends ContentProvider {
|
|||
mCursor = eventDbHelper.query();
|
||||
break;
|
||||
}
|
||||
case EVENT_WITH_ID: {
|
||||
mCursor = eventDbHelper.query(uri);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
}
|
||||
|
@ -42,6 +47,8 @@ public class EventProvider extends ContentProvider {
|
|||
switch (match) {
|
||||
case EVENT:
|
||||
return EventContract.EventEntry.CONTENT_ITEM_TYPE;
|
||||
case EVENT_WITH_ID:
|
||||
return EventContract.EventEntry.CONTENT_ITEM_TYPE;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
}
|
||||
|
@ -117,7 +124,7 @@ public class EventProvider extends ContentProvider {
|
|||
|
||||
// For each type of URI you want to add, create a corresponding code.
|
||||
matcher.addURI(authority, EventContract.PATH_EVENT, EVENT);
|
||||
|
||||
matcher.addURI(authority, EventContract.PATH_EVENT + "/#", EVENT_WITH_ID);
|
||||
return matcher;
|
||||
}
|
||||
}
|
||||
|
|
7
app/src/main/res/layout/activity_detail.xml
Normal file
7
app/src/main/res/layout/activity_detail.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/event_detail_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="no.nilsnh.uibevents.DetailActivity"
|
||||
tools:ignore="MergeRootFrame" />
|
67
app/src/main/res/layout/fragment_detail.xml
Normal file
67
app/src/main/res/layout/fragment_detail.xml
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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">
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/list_item_title_textview"
|
||||
android:id="@+id/list_item_title_textview"
|
||||
android:padding="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="1"
|
||||
android:gravity="fill_horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/list_item_details_textview"
|
||||
android:id="@+id/list_item_details_textview"
|
||||
android:paddingLeft="10dp"
|
||||
android:layout_weight="1.1" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/list_item_category_textview"
|
||||
android:id="@+id/textView" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/list_item_date_from_textview"
|
||||
android:id="@+id/list_item_date_from_textview"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_vertical|right" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/list_item_date_to_textview"
|
||||
android:id="@+id/list_item_date_to_textview"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_vertical|right" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -9,4 +9,6 @@
|
|||
<string name="list_item_date_to_textview">20.11.15</string>
|
||||
<string name="list_item_title_textview">The Norwegian Constitution \"VI: 1814 - 2014\"</string>
|
||||
<string name="sync_account_type">uibevents.nilsnh.no</string>
|
||||
<string name="list_item_details_textview">Studentteateret immaturus inviterer til jubileumsforestillingen \\\"Alice i Eventyrland\\\", med premiere 11. April.</string>
|
||||
<string name="title_activity_detail">activity detail label</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue