Search in sources :

Example 1 with LovelyTextInputDialog

use of com.yarolegovich.lovelydialog.LovelyTextInputDialog in project osm-contributor by jawg.

the class OfflineRegionsActivity method initFloatingActionButtons.

private void initFloatingActionButtons() {
    deleteRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (selectedRegionItem != null && selectedRegionItem.getOfflineRegion() != null) {
                int position = adapter.getOfflineRegionItems().indexOf(selectedRegionItem);
                offlineRegionManager.deleteOfflineRegion(selectedRegionItem.getOfflineRegion(), getOfflineRegionDeletedListener());
                adapter.removeOfflineRegion(selectedRegionItem);
                if (adapter.getItemCount() == 0) {
                    switchMode(Mode.NO_REGIONS);
                } else {
                    int newPosition = position == 0 ? 0 : position == adapter.getItemCount() ? adapter.getItemCount() - 1 : position - 1;
                    selectOfflineRegion(newPosition);
                }
                closeEditMenu();
            }
        }
    });
    downloadRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (selectedRegionItem != null && selectedRegionItem.getOfflineRegion() != null) {
                Intent intent = new Intent(OfflineRegionsActivity.this, OfflineRegionDownloadService.class);
                intent.putStringArrayListExtra(OfflineRegionDownloadService.LIST_PARAM + 0, convertDoubleList(selectedRegionItem.getOfflineRegion(), true));
                intent.putExtra(OfflineRegionDownloadService.SIZE_PARAM, 1);
                startService(intent);
                closeEditMenu();
            }
        }
    });
    addRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            switchMode(Mode.ADD_REGION);
        }
    });
    downloadNewRegionFloatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mapboxMap.getCameraPosition().zoom < MIN_DOWNLOAD_ZOOM) {
                Snackbar snackbar = Snackbar.make(activityView, R.string.region_to_large, Snackbar.LENGTH_LONG);
                TextView textView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
                textView.setTextColor(ContextCompat.getColor(OfflineRegionsActivity.this, R.color.error_color));
                snackbar.show();
                return;
            }
            final Intent intent = new Intent(OfflineRegionsActivity.this, OfflineRegionDownloadService.class);
            new LovelyTextInputDialog(OfflineRegionsActivity.this).setTopColorRes(R.color.colorPrimary).setTitle(R.string.enter_region_name).setIcon(R.drawable.ic_rename).setInputFilter(R.string.region_name_error, new LovelyTextInputDialog.TextFilter() {

                @Override
                public boolean check(String text) {
                    return text.length() < 20;
                }
            }).setConfirmButton(R.string.ok, new LovelyTextInputDialog.OnTextInputConfirmListener() {

                @Override
                public void onTextInputConfirmed(String text) {
                    intent.putExtra(OfflineRegionDownloadService.REGION_NAME_PARAM, text);
                    LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds;
                    intent.putStringArrayListExtra(OfflineRegionDownloadService.LIST_PARAM + 0, convertDoubleList(bounds, false));
                    intent.putExtra(OfflineRegionDownloadService.SIZE_PARAM, 1);
                    startService(intent);
                }
            }).show();
        }
    });
}
Also used : LovelyTextInputDialog(com.yarolegovich.lovelydialog.LovelyTextInputDialog) OfflineRegionDownloadService(io.jawg.osmcontributor.service.OfflineRegionDownloadService) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Intent(android.content.Intent) TextView(android.widget.TextView) MapView(com.mapbox.mapboxsdk.maps.MapView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Snackbar(android.support.design.widget.Snackbar)

Aggregations

Intent (android.content.Intent)1 Snackbar (android.support.design.widget.Snackbar)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1 LovelyTextInputDialog (com.yarolegovich.lovelydialog.LovelyTextInputDialog)1 OfflineRegionDownloadService (io.jawg.osmcontributor.service.OfflineRegionDownloadService)1