From fa3b6d9a3f408e7371be9bdd4d42e8f4cdc8a9d2 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 13 May 2016 12:56:40 +0200 Subject: [PATCH 1/2] Fixed bug when refreshing RealmResults. Added simple RecyclerView example. --- CHANGELOG.md | 7 ++ .../io/realm/RealmRecyclerViewAdapter.java | 13 ++- example/src/main/AndroidManifest.xml | 8 +- .../realm/examples/adapters/MainActivity.java | 88 +++++---------- .../examples/adapters/MyApplication.java | 33 ++++++ .../examples/adapters/model/TimeStamp.java | 3 + .../adapters/ui/DividerItemDecoration.java | 104 ++++++++++++++++++ .../ui/listview/ListViewExampleActivity.java | 93 ++++++++++++++++ .../listview}/MyListAdapter.java | 2 +- .../recyclerview/MyRecyclerViewAdapter.java | 67 +++++++++++ .../RecyclerViewExampleActivity.java | 94 ++++++++++++++++ .../src/main/res/drawable/ic_clear_24dp.xml | 9 ++ .../src/main/res/layout/activity_listview.xml | 20 ++++ example/src/main/res/layout/activity_main.xml | 24 ++-- .../main/res/layout/activity_recyclerview.xml | 16 +++ example/src/main/res/layout/row.xml | 13 +++ ...{menu_options.xml => listview_options.xml} | 0 example/src/main/res/values/styles.xml | 2 +- version.txt | 2 +- 19 files changed, 518 insertions(+), 80 deletions(-) create mode 100644 example/src/main/java/io/realm/examples/adapters/MyApplication.java create mode 100644 example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java create mode 100644 example/src/main/java/io/realm/examples/adapters/ui/listview/ListViewExampleActivity.java rename example/src/main/java/io/realm/examples/adapters/{adapter => ui/listview}/MyListAdapter.java (97%) create mode 100644 example/src/main/java/io/realm/examples/adapters/ui/recyclerview/MyRecyclerViewAdapter.java create mode 100644 example/src/main/java/io/realm/examples/adapters/ui/recyclerview/RecyclerViewExampleActivity.java create mode 100644 example/src/main/res/drawable/ic_clear_24dp.xml create mode 100644 example/src/main/res/layout/activity_listview.xml create mode 100644 example/src/main/res/layout/activity_recyclerview.xml create mode 100644 example/src/main/res/layout/row.xml rename example/src/main/res/menu/{menu_options.xml => listview_options.xml} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index df9c61e..e28af70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.2.1 + +### Bug fixes + +* Fixed crash when auto-updating RealmResults (#25). + + ## 1.2.0 ### Enhancements diff --git a/adapters/src/main/java/io/realm/RealmRecyclerViewAdapter.java b/adapters/src/main/java/io/realm/RealmRecyclerViewAdapter.java index ce6d256..9eab8ea 100644 --- a/adapters/src/main/java/io/realm/RealmRecyclerViewAdapter.java +++ b/adapters/src/main/java/io/realm/RealmRecyclerViewAdapter.java @@ -39,7 +39,7 @@ public abstract class RealmRecyclerViewAdapter listener; + private final RealmChangeListener listener; private OrderedRealmCollection adapterData; public RealmRecyclerViewAdapter(Context context, OrderedRealmCollection data, boolean autoUpdate) { @@ -51,9 +51,13 @@ public RealmRecyclerViewAdapter(Context context, OrderedRealmCollection data, this.adapterData = data; this.inflater = LayoutInflater.from(context); this.hasAutoUpdates = autoUpdate; - this.listener = hasAutoUpdates ? new RealmChangeListener() { + + // Right now don't use generics, since we need maintain two different + // types of listeners until RealmList is properly supported. + // See https://github.com/realm/realm-java/issues/989 + this.listener = hasAutoUpdates ? new RealmChangeListener() { @Override - public void onChange(BaseRealm results) { + public void onChange(Object results) { notifyDataSetChanged(); } } : null; @@ -135,9 +139,11 @@ public void updateData(OrderedRealmCollection data) { private void addListener(OrderedRealmCollection data) { if (data instanceof RealmResults) { RealmResults realmResults = (RealmResults) data; + //noinspection unchecked realmResults.addChangeListener(listener); } else if (data instanceof RealmList) { RealmList realmList = (RealmList) data; + //noinspection unchecked realmList.realm.handlerController.addChangeListenerAsWeakReference(listener); } else { throw new IllegalArgumentException("RealmCollection not supported: " + data.getClass()); @@ -150,6 +156,7 @@ private void removeListener(OrderedRealmCollection data) { realmResults.removeChangeListener(listener); } else if (data instanceof RealmList) { RealmList realmList = (RealmList) data; + //noinspection unchecked realmList.realm.handlerController.removeWeakChangeListener(listener); } else { throw new IllegalArgumentException("RealmCollection not supported: " + data.getClass()); diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 956be29..d622afb 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"> @@ -16,7 +17,12 @@ - + + diff --git a/example/src/main/java/io/realm/examples/adapters/MainActivity.java b/example/src/main/java/io/realm/examples/adapters/MainActivity.java index bdb4b22..bf7dcf4 100644 --- a/example/src/main/java/io/realm/examples/adapters/MainActivity.java +++ b/example/src/main/java/io/realm/examples/adapters/MainActivity.java @@ -17,80 +17,50 @@ package io.realm.examples.adapters; import android.app.Activity; +import android.content.Intent; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; +import android.support.v7.app.AppCompatActivity; import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; +import android.view.ViewGroup; +import android.widget.Button; -import io.realm.Realm; -import io.realm.RealmConfiguration; -import io.realm.RealmResults; -import io.realm.examples.adapters.adapter.MyListAdapter; -import io.realm.examples.adapters.model.TimeStamp; +import java.util.Map; +import java.util.TreeMap; -public class MainActivity extends Activity { +import io.realm.examples.adapters.ui.listview.ListViewExampleActivity; +import io.realm.examples.adapters.ui.recyclerview.RecyclerViewExampleActivity; - private Realm realm; +public class MainActivity extends AppCompatActivity { + + private ViewGroup container; + private final TreeMap> buttons = new TreeMap>() {{ + put("ListView", ListViewExampleActivity.class); + put("RecyclerView", RecyclerViewExampleActivity.class); + }}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build(); - Realm.deleteRealm(realmConfig); // Resets the Realm between app starts - realm = Realm.getInstance(realmConfig); - - // RealmResults are "live" views, that are automatically kept up to date, even when changes happen - // on a background thread. The RealmBaseAdapter will automatically keep track of changes and will - // automatically refresh when a change is detected. - RealmResults timeStamps = realm.where(TimeStamp.class).findAll(); - final MyListAdapter adapter = new MyListAdapter(this, timeStamps); - - ListView listView = (ListView) findViewById(R.id.listView); - listView.setAdapter(adapter); - listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { - final String timestamp = adapter.getItem(i).getTimeStamp(); - realm.executeTransactionAsync(new Realm.Transaction() { - @Override - public void execute(Realm realm) { - realm.where(TimeStamp.class).equalTo("timeStamp", timestamp).findAll().deleteAllFromRealm(); - } - }); - return true; - } - }); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - realm.close(); + container = (ViewGroup) findViewById(R.id.list); + setupButtons(); } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_options, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == R.id.action_add) { - final String timestamp = Long.toString(System.currentTimeMillis()); - realm.executeTransactionAsync(new Realm.Transaction() { + private void setupButtons() { + for (final Map.Entry> entry : buttons.entrySet()) { + Button button = new Button(this); + button.setText(entry.getKey()); + button.setOnClickListener(new View.OnClickListener() { @Override - public void execute(Realm realm) { - realm.createObject(TimeStamp.class).setTimeStamp(timestamp); + public void onClick(View v) { + startActivity(entry.getValue()); } }); - return true; + container.addView(button); } - return super.onOptionsItemSelected(item); + } + + private void startActivity(Class activityClass) { + startActivity(new Intent(this, activityClass)); } } diff --git a/example/src/main/java/io/realm/examples/adapters/MyApplication.java b/example/src/main/java/io/realm/examples/adapters/MyApplication.java new file mode 100644 index 0000000..e7f770b --- /dev/null +++ b/example/src/main/java/io/realm/examples/adapters/MyApplication.java @@ -0,0 +1,33 @@ +/* + * Copyright 2016 Realm Inc. + * + * 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 io.realm.examples.adapters; + +import android.app.Application; + +import io.realm.Realm; +import io.realm.RealmConfiguration; + +public class MyApplication extends Application { + + @Override + public void onCreate() { + super.onCreate(); + RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build(); + Realm.deleteRealm(realmConfig); // Delete Realm between app restarts. + Realm.setDefaultConfiguration(realmConfig); + } +} diff --git a/example/src/main/java/io/realm/examples/adapters/model/TimeStamp.java b/example/src/main/java/io/realm/examples/adapters/model/TimeStamp.java index 364fe3e..5c32008 100644 --- a/example/src/main/java/io/realm/examples/adapters/model/TimeStamp.java +++ b/example/src/main/java/io/realm/examples/adapters/model/TimeStamp.java @@ -18,6 +18,9 @@ import io.realm.RealmObject; public class TimeStamp extends RealmObject { + + public static final String TIMESTAMP = "timeStamp"; + private String timeStamp; public String getTimeStamp() { diff --git a/example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java b/example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java new file mode 100644 index 0000000..ffe8240 --- /dev/null +++ b/example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java @@ -0,0 +1,104 @@ +package io.realm.examples.adapters.ui; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +/* + * 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. + */ +public class DividerItemDecoration extends RecyclerView.ItemDecoration { + + private static final int[] ATTRS = new int[]{ + android.R.attr.listDivider + }; + + public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; + + public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; + + private Drawable mDivider; + + private int mOrientation; + + public DividerItemDecoration(Context context, int orientation) { + final TypedArray a = context.obtainStyledAttributes(ATTRS); + mDivider = a.getDrawable(0); + a.recycle(); + setOrientation(orientation); + } + + public void setOrientation(int orientation) { + if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { + throw new IllegalArgumentException("invalid orientation"); + } + mOrientation = orientation; + } + + @Override + public void onDraw(Canvas c, RecyclerView parent) { + if (mOrientation == VERTICAL_LIST) { + drawVertical(c, parent); + } else { + drawHorizontal(c, parent); + } + } + + public void drawVertical(Canvas c, RecyclerView parent) { + final int left = parent.getPaddingLeft(); + final int right = parent.getWidth() - parent.getPaddingRight(); + + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child + .getLayoutParams(); + final int top = child.getBottom() + params.bottomMargin; + final int bottom = top + mDivider.getIntrinsicHeight(); + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } + + public void drawHorizontal(Canvas c, RecyclerView parent) { + final int top = parent.getPaddingTop(); + final int bottom = parent.getHeight() - parent.getPaddingBottom(); + + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child + .getLayoutParams(); + final int left = child.getRight() + params.rightMargin; + final int right = left + mDivider.getIntrinsicHeight(); + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } + + @Override + public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { + if (mOrientation == VERTICAL_LIST) { + outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); + } else { + outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); + } + } +} \ No newline at end of file diff --git a/example/src/main/java/io/realm/examples/adapters/ui/listview/ListViewExampleActivity.java b/example/src/main/java/io/realm/examples/adapters/ui/listview/ListViewExampleActivity.java new file mode 100644 index 0000000..e054326 --- /dev/null +++ b/example/src/main/java/io/realm/examples/adapters/ui/listview/ListViewExampleActivity.java @@ -0,0 +1,93 @@ +/* + * Copyright 2016 Realm Inc. + * + * 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 io.realm.examples.adapters.ui.listview; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; + +import io.realm.Realm; +import io.realm.RealmConfiguration; +import io.realm.RealmResults; +import io.realm.examples.adapters.R; +import io.realm.examples.adapters.model.TimeStamp; + +public class ListViewExampleActivity extends AppCompatActivity { + + private Realm realm; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_listview); + realm = Realm.getDefaultInstance(); + + // RealmResults are "live" views, that are automatically kept up to date, even when changes happen + // on a background thread. The RealmBaseAdapter will automatically keep track of changes and will + // automatically refresh when a change is detected. + RealmResults timeStamps = realm.where(TimeStamp.class).findAll(); + final MyListAdapter adapter = new MyListAdapter(this, timeStamps); + + ListView listView = (ListView) findViewById(R.id.listView); + listView.setAdapter(adapter); + listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { + final String timestamp = adapter.getItem(i).getTimeStamp(); + realm.executeTransactionAsync(new Realm.Transaction() { + @Override + public void execute(Realm realm) { + realm.where(TimeStamp.class).equalTo("timeStamp", timestamp).findAll().deleteAllFromRealm(); + } + }); + return true; + } + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + realm.close(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.listview_options, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == R.id.action_add) { + final String timestamp = Long.toString(System.currentTimeMillis()); + realm.executeTransactionAsync(new Realm.Transaction() { + @Override + public void execute(Realm realm) { + realm.createObject(TimeStamp.class).setTimeStamp(timestamp); + } + }); + return true; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/example/src/main/java/io/realm/examples/adapters/adapter/MyListAdapter.java b/example/src/main/java/io/realm/examples/adapters/ui/listview/MyListAdapter.java similarity index 97% rename from example/src/main/java/io/realm/examples/adapters/adapter/MyListAdapter.java rename to example/src/main/java/io/realm/examples/adapters/ui/listview/MyListAdapter.java index 4213596..cef5bc2 100644 --- a/example/src/main/java/io/realm/examples/adapters/adapter/MyListAdapter.java +++ b/example/src/main/java/io/realm/examples/adapters/ui/listview/MyListAdapter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.realm.examples.adapters.adapter; +package io.realm.examples.adapters.ui.listview; import android.content.Context; import android.view.View; diff --git a/example/src/main/java/io/realm/examples/adapters/ui/recyclerview/MyRecyclerViewAdapter.java b/example/src/main/java/io/realm/examples/adapters/ui/recyclerview/MyRecyclerViewAdapter.java new file mode 100644 index 0000000..f24e4e7 --- /dev/null +++ b/example/src/main/java/io/realm/examples/adapters/ui/recyclerview/MyRecyclerViewAdapter.java @@ -0,0 +1,67 @@ +/* + * Copyright 2016 Realm Inc. + * + * 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 io.realm.examples.adapters.ui.recyclerview; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import io.realm.OrderedRealmCollection; +import io.realm.RealmRecyclerViewAdapter; +import io.realm.examples.adapters.R; +import io.realm.examples.adapters.model.TimeStamp; + +public class MyRecyclerViewAdapter extends RealmRecyclerViewAdapter { + + private final RecyclerViewExampleActivity activity; + + public MyRecyclerViewAdapter(RecyclerViewExampleActivity activity, OrderedRealmCollection data) { + super(activity ,data, true); + this.activity = activity; + } + + @Override + public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View itemView = inflater.inflate(R.layout.row, parent, false); + return new MyViewHolder(itemView); + } + + @Override + public void onBindViewHolder(MyViewHolder holder, int position) { + TimeStamp obj = getData().get(position); + holder.data = obj; + holder.title.setText(obj.getTimeStamp()); + } + + class MyViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener { + public TextView title; + public TimeStamp data; + + public MyViewHolder(View view) { + super(view); + title = (TextView) view.findViewById(R.id.textview); + view.setOnLongClickListener(this); + } + + @Override + public boolean onLongClick(View v) { + activity.deleteItem(data); + return true; + } + } +} \ No newline at end of file diff --git a/example/src/main/java/io/realm/examples/adapters/ui/recyclerview/RecyclerViewExampleActivity.java b/example/src/main/java/io/realm/examples/adapters/ui/recyclerview/RecyclerViewExampleActivity.java new file mode 100644 index 0000000..565d532 --- /dev/null +++ b/example/src/main/java/io/realm/examples/adapters/ui/recyclerview/RecyclerViewExampleActivity.java @@ -0,0 +1,94 @@ +/* + * Copyright 2016 Realm Inc. + * + * 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. + * + * Adopted from http://nemanjakovacevic.net/blog/english/2016/01/12/recyclerview-swipe-to-delete-no-3rd-party-lib-necessary/ + */ +package io.realm.examples.adapters.ui.recyclerview; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.Menu; +import android.view.MenuItem; +import android.view.MotionEvent; + +import io.realm.Realm; +import io.realm.examples.adapters.R; +import io.realm.examples.adapters.model.TimeStamp; +import io.realm.examples.adapters.ui.DividerItemDecoration; + +public class RecyclerViewExampleActivity extends AppCompatActivity { + + private Realm realm; + private RecyclerView recyclerView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_recyclerview); + realm = Realm.getDefaultInstance(); + recyclerView = (RecyclerView) findViewById(R.id.recycler_view); + setUpRecyclerView(); + + } + + @Override + protected void onDestroy() { + super.onDestroy(); + realm.close(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.listview_options, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == R.id.action_add) { + final String timestamp = Long.toString(System.currentTimeMillis()); + realm.executeTransactionAsync(new Realm.Transaction() { + @Override + public void execute(Realm realm) { + realm.createObject(TimeStamp.class).setTimeStamp(timestamp); + } + }); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void setUpRecyclerView() { + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.setAdapter(new MyRecyclerViewAdapter(this, realm.where(TimeStamp.class).findAllAsync())); + recyclerView.setHasFixedSize(true); + recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST)); + } + + public void deleteItem(TimeStamp item) { + final String id = item.getTimeStamp(); + realm.executeTransactionAsync(new Realm.Transaction() { + @Override + public void execute(Realm realm) { + realm.where(TimeStamp.class).equalTo(TimeStamp.TIMESTAMP, id) + .findAll() + .deleteAllFromRealm(); + } + }); + } +} \ No newline at end of file diff --git a/example/src/main/res/drawable/ic_clear_24dp.xml b/example/src/main/res/drawable/ic_clear_24dp.xml new file mode 100644 index 0000000..c558075 --- /dev/null +++ b/example/src/main/res/drawable/ic_clear_24dp.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/example/src/main/res/layout/activity_listview.xml b/example/src/main/res/layout/activity_listview.xml new file mode 100644 index 0000000..816b8c0 --- /dev/null +++ b/example/src/main/res/layout/activity_listview.xml @@ -0,0 +1,20 @@ + + + + + diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index 816b8c0..5e757dd 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -1,20 +1,16 @@ - - + android:paddingTop="@dimen/activity_vertical_margin"> - - + android:orientation="vertical"> + + diff --git a/example/src/main/res/layout/activity_recyclerview.xml b/example/src/main/res/layout/activity_recyclerview.xml new file mode 100644 index 0000000..8b726cf --- /dev/null +++ b/example/src/main/res/layout/activity_recyclerview.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/example/src/main/res/layout/row.xml b/example/src/main/res/layout/row.xml new file mode 100644 index 0000000..3c3542f --- /dev/null +++ b/example/src/main/res/layout/row.xml @@ -0,0 +1,13 @@ + + diff --git a/example/src/main/res/menu/menu_options.xml b/example/src/main/res/menu/listview_options.xml similarity index 100% rename from example/src/main/res/menu/menu_options.xml rename to example/src/main/res/menu/listview_options.xml diff --git a/example/src/main/res/values/styles.xml b/example/src/main/res/values/styles.xml index ff6c9d2..00a7ff8 100644 --- a/example/src/main/res/values/styles.xml +++ b/example/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ - diff --git a/version.txt b/version.txt index 0ba5c6f..36b57ba 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.3.0-SNAPSHOT \ No newline at end of file +1.2.1-SNAPSHOT \ No newline at end of file From 219a16bd2b83d700b6478aaf8caf2c91d11758d7 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 13 May 2016 13:06:51 +0200 Subject: [PATCH 2/2] Fix lint warnings + copyright --- .../adapters/ui/DividerItemDecoration.java | 23 ++++++++++--------- .../main/res/layout/activity_recyclerview.xml | 1 + example/src/main/res/layout/row.xml | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java b/example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java index ffe8240..5116def 100644 --- a/example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java +++ b/example/src/main/java/io/realm/examples/adapters/ui/DividerItemDecoration.java @@ -1,14 +1,3 @@ -package io.realm.examples.adapters.ui; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.View; - /* * Copyright (C) 2014 The Android Open Source Project * @@ -24,6 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +package io.realm.examples.adapters.ui; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; + public class DividerItemDecoration extends RecyclerView.ItemDecoration { private static final int[] ATTRS = new int[]{ diff --git a/example/src/main/res/layout/activity_recyclerview.xml b/example/src/main/res/layout/activity_recyclerview.xml index 8b726cf..c9730dc 100644 --- a/example/src/main/res/layout/activity_recyclerview.xml +++ b/example/src/main/res/layout/activity_recyclerview.xml @@ -8,6 +8,7 @@