Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Improve screen rotation management #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -89,7 +90,7 @@ public class StationsListActivity extends FragmentActivity implements ActionBar.
private static final String KEY_NEARBY_STATIONS = "nearbyStations";
private static final String KEY_NETWORK_ID = "network-id";

private static final int PICK_NETWORK_REQUEST = 1;
protected static final int PICK_NETWORK_REQUEST = 1;

private BikeNetwork bikeNetwork;
private ArrayList<Station> stations;
Expand All @@ -110,6 +111,7 @@ public class StationsListActivity extends FragmentActivity implements ActionBar.
private StationsListFragment allStationsFragment;
private StationsListFragment favoriteStationsFragment;
private StationsListFragment nearbyStationsFragment;
private String fragTags[] = {null, null, null};

private SwipeRefreshLayout refreshLayout;
@Override
Expand Down Expand Up @@ -173,24 +175,8 @@ public void onPageScrollStateChanged(int state) {
setDBLastUpdateText();

if (firstRun) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.welcome_dialog_message);
builder.setTitle(R.string.welcome_dialog_title);
builder.setPositiveButton(R.string.welcome_dialog_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(StationsListActivity.this, BikeNetworksListActivity.class);
startActivityForResult(intent, PICK_NETWORK_REQUEST);
}
});
builder.setNegativeButton(R.string.welcome_dialog_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
FragmentManager fm = getSupportFragmentManager();
WelcomeDialogFragment.getInstance().show(fm, "fragment_welcome");
} else {
if (savedInstanceState != null) {
bikeNetwork = (BikeNetwork) savedInstanceState.getSerializable(KEY_BIKE_NETWORK);
Expand Down Expand Up @@ -565,16 +551,33 @@ public CharSequence getPageTitle(int position) {
}
}

@Override
public Object instantiateItem(ViewGroup container, int position)
{
Fragment frag = (Fragment) super.instantiateItem(container, position);
fragTags[position] = frag.getTag();
return frag;
}

public void updateAllStationsListFragment(ArrayList<Station> stations) {
allStationsFragment.updateStationsList(stations);
if(fragTags[2] != null) {
StationsListFragment frgt = (StationsListFragment) getSupportFragmentManager().findFragmentByTag(fragTags[2]);
frgt.updateStationsList(stations);
}
}

public void updateFavoriteStationsFragment(ArrayList<Station> stations) {
favoriteStationsFragment.updateStationsList(stations);
if(fragTags[1] != null) {
StationsListFragment frgt = (StationsListFragment) getSupportFragmentManager().findFragmentByTag(fragTags[1]);
frgt.updateStationsList(stations);
}
}

public void updateNearbyStationsFragment(ArrayList<Station> stations) {
nearbyStationsFragment.updateStationsList(stations);
if(fragTags[0] != null) {
StationsListFragment frgt = (StationsListFragment) getSupportFragmentManager().findFragmentByTag(fragTags[0]);
frgt.updateStationsList(stations);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This file is part of OpenBikeSharing.
*
* OpenBikeSharing is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenBikeSharing is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenBikeSharing. If not, see <http://www.gnu.org/licenses/>.
*/

package be.brunoparmentier.openbikesharing.app.activities;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

import be.brunoparmentier.openbikesharing.app.R;

public class WelcomeDialogFragment extends DialogFragment {

public static WelcomeDialogFragment instance = null;

public static WelcomeDialogFragment getInstance() {
if(instance == null) {
instance = new WelcomeDialogFragment();
}
return instance;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.welcome_dialog_message);
builder.setTitle(R.string.welcome_dialog_title);
builder.setPositiveButton(R.string.welcome_dialog_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(getActivity(), BikeNetworksListActivity.class);
getActivity().startActivityForResult(intent, StationsListActivity.PICK_NETWORK_REQUEST);
}
});
builder.setNegativeButton(R.string.welcome_dialog_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getActivity().finish();
}
});
return builder.create();
}

}