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

Commit 6cce0dfd authored by Marcus Wolschon's avatar Marcus Wolschon
Browse files

Merge pull request #108 from MarcusWolschon/master

Allow filtering in folder-list with Android 4 devices (no menu  key anymore)
parents de9d934b 2bfe1f45
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -35,6 +35,11 @@
            android:id="@+id/list_folders"
            android:title="@string/refresh_folders_action"
            android:icon="@drawable/ic_menu_refresh"
         />
           <item
            android:id="@+id/filter_folders"
            android:title="@string/filter_folders_action"
            android:icon="@drawable/ic_menu_search"
         />
        
        </menu>
+5 −0
Original line number Diff line number Diff line
@@ -31,6 +31,11 @@
            android:title="@string/refresh_folders_action"
            android:icon="@drawable/ic_menu_refresh"
         />
           <item
            android:id="@+id/filter_folders"
            android:title="@string/filter_folders_action"
            android:icon="@drawable/ic_menu_search"
         />
        
    <!--     </menu>
    </item>-->
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@
    <string name="send_messages_action">Nachricht senden</string>
    <string name="list_folders_action">Ordnerliste</string>
    <string name="refresh_folders_action">Ordnerliste aktualisieren</string>
    <string name="filter_folders_action">Finde Ordner</string>
    <string name="mark_all_as_read_action">Alle als gelesen markieren</string>
    <string name="add_account_action">Konto hinzufügen</string>
    <string name="compose_action">Verfassen</string>
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@
    <string name="send_messages_action">Send messages</string>
    <string name="list_folders_action">Folder list</string>
    <string name="refresh_folders_action">Refresh folders</string>
    <string name="filter_folders_action">Find folder</string>
    <string name="mark_all_as_read_action">Mark all messages as read</string>
    <string name="add_account_action">Add account</string>
    <string name="compose_action">Compose</string>
+67 −0
Original line number Diff line number Diff line

package com.fsck.k9.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -11,6 +15,7 @@ import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.ListView;
import android.widget.TextView;
@@ -196,11 +201,73 @@ public class ChooseFolder extends K9ListActivity {
            setDisplayMode(FolderMode.ALL);
            return true;
        }

        case R.id.list_folders: {
            onRefresh();

            return true;
        }
        case R.id.filter_folders: {
        	onEnterFilter();
        }
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }


    private void onRefresh() {

        MessagingController.getInstance(getApplication()).listFolders(mAccount, true, mListener);

    }

    /**
     * Show an alert with an input-field for a filter-expression.
     * Filter {@link #mAdapter} with the user-input.
     */
    private void onEnterFilter() {
    	final AlertDialog.Builder filterAlert = new AlertDialog.Builder(this);

    	final EditText input = new EditText(this);
    	input.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				mAdapter.getFilter().filter(input.getText().toString());
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}
			
			@Override
			public void afterTextChanged(Editable s) {
			}
		});
    	input.setHint(R.string.folder_list_filter_hint);
    	filterAlert.setView(input);

    	filterAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    		public void onClick(DialogInterface dialog, int whichButton) {
    			String value = input.getText().toString().trim();
    			mAdapter.getFilter().filter(value);
    		}
    	});

    	filterAlert.setNegativeButton("Cancel",
    			new DialogInterface.OnClickListener() {
    		public void onClick(DialogInterface dialog, int whichButton) {
    			mAdapter.getFilter().filter("");
    		}
    	});

    	filterAlert.show();

    }

    private void setDisplayMode(FolderMode aMode) {
        mMode = aMode;
        // invalidate the current filter as it is working on an inval
Loading