Skip to content

Commit

Permalink
Merge pull request #2 from stefan-niedermann/RecyclerView
Browse files Browse the repository at this point in the history
Recycler view
  • Loading branch information
HeaDBanGer84 committed Jan 21, 2016
2 parents bc30f1f + f50cf44 commit 795be48
Show file tree
Hide file tree
Showing 17 changed files with 278 additions and 128 deletions.
6 changes: 6 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/gridlayout-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.commit451/bypasses/1.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/8.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
Expand All @@ -87,6 +90,9 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="play-services-basement-8.1.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="play-services-appindexing-8.1.0" level="project" />
<orderEntry type="library" exported="" name="gridlayout-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="bypasses-1.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:gridlayout-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,10 @@
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.util.SparseBooleanArray;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Calendar;
Expand All @@ -29,7 +27,7 @@
import it.niedermann.owncloud.notes.util.ICallback;

public class NotesListViewActivity extends AppCompatActivity implements
OnItemClickListener, View.OnClickListener {
ItemAdapter.NoteClickListener, View.OnClickListener {

public final static String SELECTED_NOTE = "it.niedermann.owncloud.notes.clicked_note";
public final static String CREATED_NOTE = "it.niedermann.owncloud.notes.created_notes";
Expand All @@ -41,7 +39,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
private final static int server_settings = 2;
private final static int about = 3;

private ListView listView = null;
private RecyclerView listView = null;
private ItemAdapter adapter = null;
private ActionMode mActionMode;
private SwipeRefreshLayout swipeRefreshLayout = null;
Expand Down Expand Up @@ -171,44 +169,10 @@ public void setListView(List<Note> noteList) {
}

adapter = new ItemAdapter(getApplicationContext(), itemList);
listView = (ListView) findViewById(R.id.list_view);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
ItemAdapter.setNoteClickListener(this);
listView = (RecyclerView) findViewById(R.id.list_view);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
onListItemSelect(position);
return true;
}
});
}

/**
* A short click on one list item. Creates a new instance of NoteActivity.
*/
@Override
public void onItemClick(AdapterView<?> parentView, View childView,
int position, long id) {
Item item = adapter.getItem(position);
if (!item.isSection()) {
listView.setItemChecked(position, !listView.isItemChecked(position));
if (listView.getCheckedItemCount() < 1) {
removeSelection();
Intent intent = new Intent(getApplicationContext(),
NoteActivity.class);
if (!item.isSection()) {
intent.putExtra(SELECTED_NOTE, (Note) item);
intent.putExtra(SELECTED_NOTE_POSITION, position);
startActivityForResult(intent, show_single_note_cmd);
}
} else { // perform long click if already something is selected
onListItemSelect(position);
}
} else {
listView.setItemChecked(position, false);
}
listView.setLayoutManager(new LinearLayoutManager(this));
}

/**
Expand Down Expand Up @@ -261,7 +225,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Note createdNote = (Note) data.getExtras().getSerializable(
CREATED_NOTE);
adapter.insert(createdNote, 0);
adapter.add(createdNote);
}
} else if (requestCode == show_single_note_cmd) {
if (resultCode == RESULT_OK || resultCode == RESULT_FIRST_USER) {
Expand All @@ -271,7 +235,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Note editedNote = (Note) data.getExtras().getSerializable(
NoteActivity.EDIT_NOTE);
adapter.insert(editedNote, 0);
adapter.add(editedNote);
}
}
} else if (requestCode == server_settings) {
Expand All @@ -287,16 +251,18 @@ public void onFinish() {
}
}

/**
* Long click on one item in the list view. It starts the Action Mode and allows selecting more
* items and execute bulk functions (e. g. delete)
*
* @param position int - position of the clicked item
*/
private void onListItemSelect(int position) {
if (!adapter.getItem(position).isSection()) {
listView.setItemChecked(position, !listView.isItemChecked(position));
int checkedItemCount = listView.getCheckedItemCount();
@Override
public void onNoteClick(int position, View v) {
if (mActionMode != null) {
if (!adapter.select(position)) {
v.setSelected(false);
adapter.deselect(position);
} else {
v.setSelected(true);
}
mActionMode.setTitle(String.valueOf(adapter.getSelected().size())
+ " " + getString(R.string.ab_selected));
int checkedItemCount = adapter.getSelected().size();
boolean hasCheckedItems = checkedItemCount > 0;

if (hasCheckedItems && mActionMode == null) {
Expand All @@ -312,25 +278,34 @@ private void onListItemSelect(int position) {
// there no selected items, finish the actionMode
mActionMode.finish();
}

if (mActionMode != null) {
mActionMode.setTitle(String.valueOf(listView.getCheckedItemCount())
+ " " + getString(R.string.ab_selected));
}
} else {
listView.setItemChecked(position, false);


Intent intent = new Intent(getApplicationContext(),
NoteActivity.class);

Item item = adapter.getItem(position);
intent.putExtra(SELECTED_NOTE, (Note) item);
intent.putExtra(SELECTED_NOTE_POSITION, position);
Log.v("Note",
"notePosition | NotesListViewActivity wurde abgesendet "
+ position);
startActivityForResult(intent, show_single_note_cmd);

}
}

/**
* Removes all selections.
*/
private void removeSelection() {
SparseBooleanArray checkedItemPositions = listView
.getCheckedItemPositions();
for (int i = 0; i < checkedItemPositions.size(); i++) {
listView.setItemChecked(i, false);
@Override
public boolean onNoteLongClick(int position, View v) {
boolean selected = adapter.select(position);
if (selected) {
v.setSelected(selected);
mActionMode = startSupportActionMode(new MultiSelectedActionModeCallback());
int checkedItemCount = adapter.getSelected().size();
mActionMode.setTitle(String.valueOf(checkedItemCount)
+ " " + getString(R.string.ab_selected));
}
return selected;
}

/**
Expand Down Expand Up @@ -361,15 +336,11 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_delete:
SparseBooleanArray checkedItemPositions = listView
.getCheckedItemPositions();
for (int i = (checkedItemPositions.size() - 1); i >= 0; i--) {
if (checkedItemPositions.valueAt(i)) {
Note note = (Note) adapter.getItem(checkedItemPositions
.keyAt(i));
db.deleteNoteAndSync(note.getId());
adapter.remove(note);
}
List<Integer> selection = adapter.getSelected();
for (Integer i : selection) {
Note note = (Note) adapter.getItem(i);
db.deleteNoteAndSync(note.getId());
adapter.remove(note);
}
mode.finish(); // Action picked, so close the CAB
return true;
Expand All @@ -380,7 +351,7 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {

@Override
public void onDestroyActionMode(ActionMode mode) {
removeSelection();
adapter.clearSelection();
mActionMode = null;
adapter.notifyDataSetChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import android.content.Intent;
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.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RemoteViews;

import java.util.ArrayList;
Expand All @@ -28,7 +29,7 @@ public class SelectSingleNoteActivity extends AppCompatActivity implements Adapt

int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
private NoteSQLiteOpenHelper db = null;
private ListView listView = null;
private RecyclerView listView = null;
private ItemAdapter adapter = null;

@Override
Expand Down Expand Up @@ -65,10 +66,10 @@ private void setListView(List<Note> noteList) {
List<Item> itemList = new ArrayList<>();
itemList.addAll(noteList);
adapter = new ItemAdapter(getApplicationContext(), itemList);
listView = (ListView) findViewById(R.id.select_single_note_list_view);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView = (RecyclerView) findViewById(R.id.select_single_note_list_view);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
listView.setLayoutManager(new LinearLayoutManager(this));
//httpslistView.setOnItemClickListener(this);
}

@Override
Expand Down
Loading

0 comments on commit 795be48

Please sign in to comment.