Compare commits
No commits in common. "39779040ad1ad1786fd9f1b8fd9f61ed30698cdb" and "eb61b3fdb7b8f66b8a81bdc83210edd033c3fd7d" have entirely different histories.
39779040ad
...
eb61b3fdb7
@ -9,22 +9,15 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.MyWeather">
|
||||
<activity
|
||||
android:name=".ShowTemparature"
|
||||
<!-- Adding an attribute to remove the app bar (.NoActionBar) only in the activity that allows the user to add a city, also declaring
|
||||
the mainActivity as a parent of AddCity activity in order to go back to the mainActivity screen-->
|
||||
<activity android:name=".AddCity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/Theme.MyWeather.NoActionBar"></activity>
|
||||
<!--
|
||||
Adding an attribute to remove the app bar (.NoActionBar) only in the activity that allows the user to add a city, also declaring
|
||||
the mainActivity as a parent of AddCity activity in order to go back to the mainActivity screen
|
||||
-->
|
||||
<activity
|
||||
android:name=".AddCity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/Theme.MyWeather.NoActionBar"></activity>
|
||||
android:theme="@style/Theme.MyWeather.NoActionBar">
|
||||
</activity>
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
@ -4,7 +4,6 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
@ -17,6 +16,10 @@ public class AddCity extends AppCompatActivity {
|
||||
|
||||
private EditText cityName;
|
||||
|
||||
// - Define shared preferences var -
|
||||
SharedPreferences sharedPreferences;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
@ -36,15 +39,26 @@ public class AddCity extends AppCompatActivity {
|
||||
{
|
||||
cityName = (EditText) findViewById(R.id.editTextNewCity);
|
||||
final String newCityString = cityName.getEditableText().toString();
|
||||
if(newCityString.isEmpty())
|
||||
if(newCityString.length() == 0)
|
||||
{
|
||||
cityName.setError("Please, enter a city name");
|
||||
}
|
||||
else {
|
||||
else
|
||||
|
||||
// - Load Shared Preferences (named 'prefs') -
|
||||
sharedPreferences = getSharedPreferences("prefs", Context.MODE_PRIVATE);
|
||||
|
||||
// - Now the ImageView has to be hidden, so write it into the shared preferences -
|
||||
// - Put value '0' into the preference 'umbrella_visible' of the shared preference book called 'prefs'
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putInt("umbrella_visible", 0);
|
||||
editor.apply();
|
||||
|
||||
saveCity(newCityString);
|
||||
resetForm();
|
||||
openAddCityPage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -59,10 +73,4 @@ public class AddCity extends AppCompatActivity {
|
||||
CityRepository.getInstance(this).addCity(new City(cityName));
|
||||
}
|
||||
|
||||
public void openAddCityPage()
|
||||
{
|
||||
Intent intent = new Intent(AddCity.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,59 +2,31 @@ package fr.romanet.vj.apps.myweather;
|
||||
|
||||
import android.content.*;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
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 MainActivity extends AppCompatActivity {
|
||||
|
||||
private ListView listViewCityNames;
|
||||
private FloatingActionButton buttonPlus;
|
||||
private ImageView imgPara;
|
||||
private TextView addCityText;
|
||||
// - Umbrella ImageView
|
||||
public static ImageView imgPara;
|
||||
|
||||
// - Is used to store the shared preference value of umbrella visibility
|
||||
public int umbrella_visible;
|
||||
|
||||
// - Define shared preferences var -
|
||||
SharedPreferences sharedPreferences;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
listViewCityNames = findViewById(R.id.listeCity);
|
||||
buttonPlus = (FloatingActionButton) findViewById(R.id.plusButton);
|
||||
imgPara = (ImageView) findViewById(R.id.imageView);
|
||||
addCityText = (TextView) findViewById(R.id.textViewAddCity);
|
||||
|
||||
initialisingComponents();
|
||||
|
||||
listViewCityNames.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
String currentCityName = adapterView.getItemAtPosition(i).toString();
|
||||
Intent intent = new Intent(MainActivity.this, ShowTemparature.class);
|
||||
intent.putExtra( "cityName", currentCityName);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
FloatingActionButton buttonPlus = (FloatingActionButton) findViewById(R.id.plusButton);
|
||||
buttonPlus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
@ -62,39 +34,46 @@ public class MainActivity extends AppCompatActivity {
|
||||
openAddCityPage();
|
||||
}
|
||||
});
|
||||
|
||||
// - Assign Activity ImageView to var -
|
||||
imgPara = (ImageView) findViewById(R.id.imageView);
|
||||
|
||||
// - Load Shared Preferences (named 'prefs') -
|
||||
sharedPreferences = getSharedPreferences("prefs", Context.MODE_PRIVATE);
|
||||
|
||||
// - Try to retrieve 'umbrella_visible', if not set return 3 -
|
||||
umbrella_visible = sharedPreferences.getInt("umbrella_visible", 3);
|
||||
|
||||
// - If preference not yet defined, set value to 1 (visible) -
|
||||
if (umbrella_visible == 3){
|
||||
|
||||
// - Put value '1' into the preference 'umbrella_visible' of the shared preference book called 'prefs'
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putInt("umbrella_visible", 1);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
Log.d("DEBUG1 -> create", Integer.toString(umbrella_visible));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//initList();
|
||||
}
|
||||
|
||||
public void initialisingComponents()
|
||||
{
|
||||
final List<City> city = CityRepository.getInstance(this).getCity();
|
||||
if(city.isEmpty())
|
||||
{
|
||||
listViewCityNames.setVisibility(View.GONE);
|
||||
}
|
||||
else{
|
||||
// - Load Shared Preferences (named 'prefs') -
|
||||
sharedPreferences = getSharedPreferences("prefs", Context.MODE_PRIVATE);
|
||||
|
||||
// - Try to retrieve 'umbrella_visible', if not set return 3 -
|
||||
umbrella_visible = sharedPreferences.getInt("umbrella_visible", 3);
|
||||
Log.d("DEBUG1 -> resume", Integer.toString(umbrella_visible));
|
||||
|
||||
// - If 'umbrella_visible' is equal to '0', we have to hide the ImageView -
|
||||
if(umbrella_visible == 0){
|
||||
|
||||
// - Hide ImageView -
|
||||
imgPara.setVisibility(View.GONE);
|
||||
addCityText.setVisibility(View.GONE);
|
||||
}
|
||||
initList();
|
||||
}
|
||||
|
||||
public void initList()
|
||||
{
|
||||
final List<City> city = CityRepository.getInstance(this).getCity();
|
||||
ArrayList<String> listeExample = new ArrayList<String>();
|
||||
for(int i = 0; i < city.size(); i++)
|
||||
{
|
||||
listeExample.add("" + city.get(i).nameCity);
|
||||
}
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, listeExample);
|
||||
listViewCityNames.setAdapter(adapter);
|
||||
}
|
||||
|
||||
public void openAddCityPage()
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
package fr.romanet.vj.apps.myweather;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class ShowTemparature extends AppCompatActivity {
|
||||
|
||||
private String currentCityName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_temparature);
|
||||
|
||||
currentCityName = (String) getIntent().getExtras().get("cityName");
|
||||
|
||||
Toolbar toolbarAddCity = (Toolbar) findViewById(R.id.toolbarCityTemp);
|
||||
toolbarAddCity.setTitle(currentCityName);
|
||||
setSupportActionBar(toolbarAddCity);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,6 @@
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appBarLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/Theme.MyWeather.AppBarOverlay"
|
||||
@ -25,7 +24,7 @@
|
||||
app:srcCompat="@drawable/ic_baseline_umbrella_24" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewAddCity"
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="51dp"
|
||||
android:gravity="center"
|
||||
@ -47,11 +46,4 @@
|
||||
app:rippleColor="#FFFFFF"
|
||||
app:srcCompat="@android:drawable/ic_input_add"/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listeCity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
|
||||
tools:layout_editor_absoluteX="6dp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ShowTemparature">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/Theme.MyWeather.AppBarOverlay"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbarCityTemp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:clickable="false"
|
||||
android:minHeight="60dp"
|
||||
app:popupTheme="@style/Theme.MyWeather.PopupOverlay" />
|
||||
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue
Block a user