Search in sources :

Example 1 with MyAddressAdapter

use of com.junjunguo.pocketmaps.fragments.MyAddressAdapter in project PocketMaps by junjunguo.

the class GeocodeActivity method showAddresses.

private RecyclerView showAddresses(final List<Address> list, final boolean viewOnly) {
    setContentView(R.layout.activity_addresses);
    OnClickAddressListener l = new OnClickAddressListener() {

        @Override
        public void onClick(Address addr) {
            log("Address selected: " + addr);
            if (viewOnly) {
                GeocodeActivity.backToListViewOnly = true;
                GeocodeActivity.backToListData = list;
            }
            GeocodeActivity.this.finish();
            if (callbackListener != null) {
                callbackListener.onClick(addr);
            }
        }
    };
    OnClickAddressListener detL = new OnClickAddressListener() {

        @Override
        public void onClick(Address addr) {
            log("Address details selected: " + addr);
            backToListData = list;
            backToListViewOnly = viewOnly;
            if (viewOnly) {
                GeocodeActivity.this.showAddressDetails(EditType.ViewOnly, addr);
            } else {
                GeocodeActivity.this.showAddressDetails(EditType.ViewEdit, addr);
            }
        }
    };
    MyAddressAdapter adapter = new MyAddressAdapter(list, l, detL);
    RecyclerView listView = (RecyclerView) findViewById(R.id.my_addr_recycler_view);
    listView.setHasFixedSize(true);
    // use a linear layout manager
    LinearLayoutManager layoutManager = new LinearLayoutManager(this.getApplicationContext());
    layoutManager.setOrientation(RecyclerView.VERTICAL);
    listView.setLayoutManager(layoutManager);
    listView.setItemAnimator(new DefaultItemAnimator());
    listView.setAdapter(adapter);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.my_addr_add_fab);
    if (!isFavouritesView()) {
        fab.setVisibility(View.INVISIBLE);
    } else {
        fab.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                log("Plus selected!");
                showAddressDetails(EditType.EditOnly, null);
            }
        });
    }
    if (!viewOnly) {
        addDeleteItemHandler(listView);
    }
    ;
    return listView;
}
Also used : Address(android.location.Address) MyAddressAdapter(com.junjunguo.pocketmaps.fragments.MyAddressAdapter) OnClickAddressListener(com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) RecyclerView(androidx.recyclerview.widget.RecyclerView) OnClickListener(android.view.View.OnClickListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 2 with MyAddressAdapter

use of com.junjunguo.pocketmaps.fragments.MyAddressAdapter in project PocketMaps by junjunguo.

the class GeocodeActivity method showAddresses.

private RecyclerView showAddresses(List<Address> list) {
    setContentView(R.layout.activity_addresses);
    OnClickAddressListener l = new OnClickAddressListener() {

        @Override
        public void onClick(Address addr) {
            log("Address selected: " + addr);
            GeocodeActivity.this.finish();
            if (callbackListener != null) {
                callbackListener.onClick(addr);
            }
        }
    };
    MyAddressAdapter adapter = new MyAddressAdapter(list, l);
    RecyclerView listView = (RecyclerView) findViewById(R.id.my_addr_recycler_view);
    listView.setHasFixedSize(true);
    // use a linear layout manager
    LinearLayoutManager layoutManager = new LinearLayoutManager(this.getApplicationContext());
    layoutManager.setOrientation(LinearLayout.VERTICAL);
    listView.setLayoutManager(layoutManager);
    listView.setItemAnimator(new DefaultItemAnimator());
    listView.setAdapter(adapter);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.my_addr_add_fab);
    if (locations == null) {
        fab.setVisibility(View.INVISIBLE);
    } else {
        fab.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                log("Plus selected!");
                showFavAdd();
            }
        });
    }
    return listView;
}
Also used : Address(android.location.Address) MyAddressAdapter(com.junjunguo.pocketmaps.fragments.MyAddressAdapter) OnClickAddressListener(com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) OnClickListener(android.view.View.OnClickListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 3 with MyAddressAdapter

use of com.junjunguo.pocketmaps.fragments.MyAddressAdapter in project PocketMaps by junjunguo.

the class GeocodeActivity method addDeleteItemHandler.

private void addDeleteItemHandler(RecyclerView recView) {
    final MyAddressAdapter recAdapter = (MyAddressAdapter) recView.getAdapter();
    OnItemClickListener delL = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Address curAddr = recAdapter.remove(position);
            favourites.remove(curAddr.getAddressLine(0));
            String mapDir = Variable.getVariable().getMapsFolder().getParent();
            String propFile = new File(mapDir, FAV_PROP_FILE).getPath();
            try (FileOutputStream fos = new FileOutputStream(propFile)) {
                favourites.store(fos, "List of favourites");
            } catch (IOException e) {
                logUser("Unable to store favourites");
            }
        }
    };
    MainActivity.addDeleteItemHandler(this, recView, delL);
}
Also used : MyAddressAdapter(com.junjunguo.pocketmaps.fragments.MyAddressAdapter) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Address(android.location.Address) FileOutputStream(java.io.FileOutputStream) AdapterView(android.widget.AdapterView) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) File(java.io.File)

Aggregations

Address (android.location.Address)3 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 MyAddressAdapter (com.junjunguo.pocketmaps.fragments.MyAddressAdapter)3 OnClickListener (android.view.View.OnClickListener)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 OnClickAddressListener (com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1