// Path: app/src/main/java/org/noorganization/instalist/view/sorting/AlphabeticalUnitComparator.java
// public class AlphabeticalUnitComparator implements Comparator<Unit> {
// 
//     private static AlphabeticalUnitComparator sInstance;
// 
//     @Override
//     public int compare(Unit _lhs, Unit _rhs) {
//         if (_lhs.equals(_rhs)) {
//             return 0;
//         }
//         return Collator.getInstance().compare(_lhs.mName, _rhs.mName);
//     }
// 
//     public static AlphabeticalUnitComparator getInstance() {
//         if (sInstance == null) {
//             sInstance = new AlphabeticalUnitComparator();
//         }
//         return sInstance;
//     }
// }


import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import org.noorganization.instalist.R;
import org.noorganization.instalist.model.Unit;
import org.noorganization.instalist.view.sorting.AlphabeticalUnitComparator;
import java.util.ArrayList;
/*
 * Copyright 2016 Tino Siegmund, Michael Wodniok
 *
 * 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 org.noorganization.instalist.view.listadapter;




/**
 * An Adapter that is based on a always alphabetically sorted List for Units.
 * Created by daMihe on 22.07.2015.
 */
public class UnitEditorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final int TYPE_TEXTVIEW = 0;
    private static final int TYPE_EDITTEXT = 1;

    private Activity mActivity;
    private List<Unit> mUnderLyingUnits;
    private ActionMode.Callback mEditingMode;

    private int mEditingPosition;

    public UnitEditorAdapter(Activity _activity, List<Unit> _elements, ActionMode.Callback _editorCallback) {
        mActivity = _activity;
        mUnderLyingUnits = new ArrayList<>();
        if (_elements != null) {
            mUnderLyingUnits.addAll(_elements);
            Collections.sort(mUnderLyingUnits, AlphabeticalUnitComparator.getInstance());
        }
        mEditingPosition = -1;
        mEditingMode = _editorCallback;
    }

    public void add(Unit _unit) {
        if (_unit == null) {
            return;
        }

// Path: app/src/main/java/org/noorganization/instalist/view/sorting/AlphabeticalUnitComparator.java
// public class AlphabeticalUnitComparator implements Comparator<Unit> {
// 
//     private static AlphabeticalUnitComparator sInstance;
// 
//     @Override
//     public int compare(Unit _lhs, Unit _rhs) {
//         if (_lhs.equals(_rhs)) {
//             return 0;
//         }
//         return Collator.getInstance().compare(_lhs.mName, _rhs.mName);
//     }
// 
//     public static AlphabeticalUnitComparator getInstance() {
//         if (sInstance == null) {
//             sInstance = new AlphabeticalUnitComparator();
//         }
//         return sInstance;
//     }
// }


// Path: app/src/main/java/org/noorganization/instalist/view/listadapter/UnitEditorAdapter.java
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import org.noorganization.instalist.R;
import org.noorganization.instalist.model.Unit;
import org.noorganization.instalist.view.sorting.AlphabeticalUnitComparator;
import java.util.ArrayList;

/*
 * Copyright 2016 Tino Siegmund, Michael Wodniok
 *
 * 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 org.noorganization.instalist.view.listadapter;




/**
 * An Adapter that is based on a always alphabetically sorted List for Units.
 * Created by daMihe on 22.07.2015.
 */
public class UnitEditorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final int TYPE_TEXTVIEW = 0;
    private static final int TYPE_EDITTEXT = 1;

    private Activity mActivity;
    private List<Unit> mUnderLyingUnits;
    private ActionMode.Callback mEditingMode;

    private int mEditingPosition;

    public UnitEditorAdapter(Activity _activity, List<Unit> _elements, ActionMode.Callback _editorCallback) {
        mActivity = _activity;
        mUnderLyingUnits = new ArrayList<>();
        if (_elements != null) {
            mUnderLyingUnits.addAll(_elements);
            Collections.sort(mUnderLyingUnits, AlphabeticalUnitComparator.getInstance());
        }
        mEditingPosition = -1;
        mEditingMode = _editorCallback;
    }

    public void add(Unit _unit) {
        if (_unit == null) {
            return;
        }

        Comparator<Unit> comparator = AlphabeticalUnitComparator.getInstance();