Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04f766d8 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

#19 Local Search

parent 1a0066d8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@
      <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" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/release" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ android {

    defaultConfig {
        applicationId "it.niedermann.owncloud.notes"
        minSdkVersion 10
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 8
        versionName "0.6.0"
+9 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
    android:versionName="0.6.0">

    <uses-sdk
        android:minSdkVersion="10"
        android:minSdkVersion="11"
        android:targetSdkVersion="23" />

    <uses-permission android:name="android.permission.INTERNET" />
@@ -28,7 +28,15 @@
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.SEARCH"/>
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable"/>
            <meta-data
                android:name="android.app.default_searchable"
                android:value="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity"/>
        </activity>
        <activity
            android:name="it.niedermann.owncloud.notes.android.activity.NoteActivity"
+37 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.android.activity;

import android.app.SearchManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -44,6 +47,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
    private ActionMode mActionMode;
    private SwipeRefreshLayout swipeRefreshLayout = null;
    private NoteSQLiteOpenHelper db = null;
    private SearchView searchView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -188,8 +192,40 @@ public class NotesListViewActivity extends AppCompatActivity implements
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_list_view, menu);
        // Associate searchable configuration with the SearchView
        final MenuItem item = menu.findItem(R.id.search);
        searchView = (SearchView) MenuItemCompat.getActionView(item);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                search(newText);
                return true;
            }
        });
        return true;
    }

    private void search(String query) {
        if (query.length() > 0) {
            setListView(db.searchNotes(query));
        } else {
            setListView(db.getNotes());
        }
        listView.scrollToPosition(0);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            search(intent.getStringExtra(SearchManager.QUERY));
        }
        super.onNewIntent(intent);
    }

    /**
     * Handels click events on the Buttons in the Action Bar.
@@ -352,6 +388,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
                    }
                    mode.finish(); // Action picked, so close the CAB
                    //after delete selection has to be cleared
                    searchView.setIconified(true);
                    setListView(db.getNotes());
                    return true;
                default:
+5 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.model;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -88,14 +89,18 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    }

    public boolean deselect(Integer position) {
        Log.v("Note", "Position: " + position);
        for (int i = 0; i < selected.size(); i++) {
            Log.v("Note", "Compare: " + selected.get(i) + " == " + position);
            if (selected.get(i) == position) {
                //position was selected and removed
                selected.remove(i);
                Log.v("Note", "Return: true");
                return true;
            }
        }
        // position was not selected
        Log.v("Note", "Return: false");
        return false;
    }

Loading