Skip to content

Commit

Permalink
added a back button on weather details activity
Browse files Browse the repository at this point in the history
  • Loading branch information
amar committed Mar 25, 2021
1 parent 72af877 commit 0fdbfef
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

Expand All @@ -22,10 +25,10 @@
* this activity shows the full screen view of a city/place weather
* this can be made prettier and more functional but for a poc this is where I am
* leaving it as of now
*
* <p>
* todo
* add owm's onecall api for this screen to show a collapsible weather forecast along with current weather data
* that will help me avoid make two api calls but onecall api response will be too heavy
* add owm's onecall api for this screen to show a collapsible weather forecast along with current weather data
* that will help me avoid make two api calls but onecall api response will be too heavy
*/
public class WeatherDetailActivity extends AppCompatActivity {
private final String TAG = Constants.TAG + "WDA";
Expand All @@ -44,6 +47,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

viewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication())).get(WeatherDetailViewModel.class);

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

Intent intent = getIntent();

String city = null;
Expand Down Expand Up @@ -140,4 +146,16 @@ private int getFavRes(boolean favourite) {
private boolean isFav(String tag) {
return FAV_TAG.equals(tag);
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
this.finish();
return true;
} else {
Log.d(TAG, "Some other id");
}

return super.onOptionsItemSelected(item);
}
}

0 comments on commit 0fdbfef

Please sign in to comment.