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();
}
});
}
Aggregations