Just cleaning the code and adding some function (like reset the form)
This commit is contained in:
parent
80a0223d9a
commit
7e869e0837
@ -5,6 +5,7 @@
|
|||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="testRunner" value="PLATFORM" />
|
<option name="testRunner" value="PLATFORM" />
|
||||||
|
<option name="disableWrapperSourceDistributionNotification" value="true" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="1.8" />
|
<option name="gradleJvm" value="1.8" />
|
||||||
|
|||||||
@ -2,41 +2,55 @@ package fr.romanet.vj.apps.myweather;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import fr.romanet.vj.apps.myweather.bo.City;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import fr.romanet.vj.apps.myweather.repository.CityRepository;
|
||||||
|
|
||||||
public class AddCity extends AppCompatActivity {
|
public class AddCity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private EditText cityName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.add_city_page);
|
setContentView(R.layout.add_city_page);
|
||||||
|
|
||||||
Toolbar toolbarAddCity = (Toolbar) findViewById(R.id.toolbarAddCity);
|
Toolbar toolbarAddCity = (Toolbar) findViewById(R.id.toolbarAddCity);
|
||||||
setSupportActionBar(toolbarAddCity);
|
setSupportActionBar(toolbarAddCity);
|
||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||||
|
|
||||||
Button button = (Button) findViewById(R.id.btnSaveCity);
|
Button button = (Button) findViewById(R.id.btnSaveCity);
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
button.setOnClickListener(new View.OnClickListener()
|
||||||
public void onClick(View v) {
|
|
||||||
EditText editTextnewCity = (EditText) findViewById(R.id.editTextNewCity);
|
|
||||||
String newCity = (String) editTextnewCity.getText().toString();
|
|
||||||
if(editTextnewCity.length() == 0)
|
|
||||||
{
|
{
|
||||||
editTextnewCity.setError("Please, enter a city name");
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
cityName = (EditText) findViewById(R.id.editTextNewCity);
|
||||||
|
final String newCityString = cityName.getEditableText().toString();
|
||||||
|
if(newCityString.length() == 0)
|
||||||
|
{
|
||||||
|
cityName.setError("Please, enter a city name");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
System.out.println(newCity);
|
saveCity(newCityString);
|
||||||
//Ajoute la ville a une base de données
|
resetForm();
|
||||||
//Prélève le texte avec le get
|
|
||||||
//S'il est vide on l'alert et on fais rien
|
|
||||||
//Sinon écran d'accueil qui change
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetForm()
|
||||||
|
{
|
||||||
|
cityName.setText(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveCity(String cityName)
|
||||||
|
{
|
||||||
|
CityRepository.getInstance(this).addCity(new City(cityName));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user