Compare commits

..

3 Commits

Author SHA1 Message Date
BGbaderguet
88101f58ca Adding some functionalitys 2020-11-14 16:06:44 +01:00
BGbaderguet
fe7a018cf4 Adding the delete string that we are going to call in the item attribute 2020-11-14 16:06:20 +01:00
BGbaderguet
fdd80aa3a5 Creation of the "delete" item that we are going to add in the toolbar 2020-11-14 16:05:34 +01:00
3 changed files with 52 additions and 0 deletions

View File

@ -1,9 +1,19 @@
package fr.romanet.vj.apps.myweather; package fr.romanet.vj.apps.myweather;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.util.ArrayList;
import java.util.List;
import fr.romanet.vj.apps.myweather.bo.City;
import fr.romanet.vj.apps.myweather.repository.CityRepository;
public class ShowTemparature extends AppCompatActivity { public class ShowTemparature extends AppCompatActivity {
@ -23,4 +33,36 @@ public class ShowTemparature extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_items, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item)
{
//We handle the click on a menu item
if (item.getItemId() == R.id.item_delete)
{
cityToDelete();
Intent intent = new Intent(ShowTemparature.this, MainActivity.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
public void cityToDelete()
{
final List<City> city = CityRepository.getInstance(this).getCity();
for(int i = 0; i < city.size(); i++)
{
if(city.get(i).nameCity.equals(currentCityName))
{
CityRepository.getInstance(this).deleteCity(city.get(i));
}
}
}
} }

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/item_delete"
android:title="@string/deleteItem"
app:showAsAction="never"/>
</menu>

View File

@ -13,5 +13,6 @@
<string name="title_activity_test_constraint_layout">TestConstraintLayout</string> <string name="title_activity_test_constraint_layout">TestConstraintLayout</string>
<string name="firstAction">Please click on the Add button in order to add a city</string> <string name="firstAction">Please click on the Add button in order to add a city</string>
<string name="deleteItem">Delete</string>
</resources> </resources>