Browse Source

Fix Bug in first launch

tags/release-v3.3
Schoumi 2 years ago
parent
commit
21eb1c2e94
2 changed files with 64 additions and 50 deletions
  1. +62
    -46
      app/src/main/java/fr/mobdev/blooddonation/activity/MainActivity.java
  2. +2
    -4
      app/src/main/java/fr/mobdev/blooddonation/fragment/InformationFragment.java

+ 62
- 46
app/src/main/java/fr/mobdev/blooddonation/activity/MainActivity.java View File

@@ -33,6 +33,7 @@ import fr.mobdev.blooddonation.fragment.PrefFragment;
import fr.mobdev.blooddonation.objects.BloodSite;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
@@ -53,6 +54,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageButton;
import android.widget.PopupMenu;

@@ -89,41 +91,41 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);


DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};

// Set the drawer toggle as the DrawerListener
mDrawerLayout.addDrawerListener(mDrawerToggle);

ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
getFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
public void onBackStackChanged() {
setupToolbar(null);
}
});

if (Database.getInstance(this).isFirstTime()) {
showEditInformation(false);
} else {
showMaps();
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};

// Set the drawer toggle as the DrawerListener
mDrawerLayout.addDrawerListener(mDrawerToggle);

ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
getFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
public void onBackStackChanged() {
setupToolbar();
}
});
}
}

@@ -144,12 +146,16 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On


private void showMaps() {
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
FragmentManager manager = getFragmentManager();
Fragment maps = MapsFragment.newInstance(postCodeUpdateListener);
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fragment_container,maps);
transaction.commit();
setupToolbar();
setupToolbar(maps);
}

private void showEditInformation(boolean modify) {
@@ -157,8 +163,16 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On

Fragment information = InformationFragment.newInstance(modify, new InformationFragment.InformationListener() {
@Override
public void onValidate() {
manager.popBackStack(null,FragmentManager.POP_BACK_STACK_INCLUSIVE);
public void onValidate(boolean isFirstTime) {
if(isFirstTime)
showMaps();
else
manager.popBackStack(null,FragmentManager.POP_BACK_STACK_INCLUSIVE);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = getCurrentFocus();
if(view == null)
view = new View(MainActivity.this);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(),0);
}
});
FragmentTransaction transaction = manager.beginTransaction();
@@ -166,7 +180,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if(modify)
transaction.addToBackStack(null);
transaction.commit();
setupToolbar();
setupToolbar(information);
}

private void showAbout() {
@@ -182,7 +196,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.replace(R.id.fragment_container, about);
transaction.addToBackStack(null);
transaction.commit();
setupToolbar();
setupToolbar(about);
}

private void showDonation() {
@@ -208,7 +222,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.replace(R.id.fragment_container, donation);
transaction.addToBackStack(null);
transaction.commit();
setupToolbar();
setupToolbar(donation);
}

private void showDonationInfo() {
@@ -219,7 +233,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.replace(R.id.fragment_container, donationInfo);
transaction.addToBackStack(null);
transaction.commit();
setupToolbar();
setupToolbar(donationInfo);
}

private void showLicence() {
@@ -230,7 +244,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.replace(R.id.fragment_container, licenceFragment);
transaction.addToBackStack(null);
transaction.commit();
setupToolbar();
setupToolbar(licenceFragment);
}

private void showNotifications() {
@@ -241,7 +255,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.replace(R.id.fragment_container, notifications);
transaction.addToBackStack(null);
transaction.commit();
setupToolbar();
setupToolbar(notifications);
}

private void showPrefs() {
@@ -256,12 +270,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.replace(R.id.fragment_container, prefs);
transaction.addToBackStack(null);
transaction.commit();
setupToolbar();
setupToolbar(prefs);
}

void setupToolbar() {
FragmentManager manager = getFragmentManager();
Fragment frag = manager.findFragmentById(R.id.fragment_container);
void setupToolbar(Fragment frag) {
if (frag == null) {
FragmentManager manager = getFragmentManager();
frag = manager.findFragmentById(R.id.fragment_container);
}
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;

@@ -410,7 +426,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
});
item.setActionView(iv);
setupToolbar();
setupToolbar(null);
return true;
}

@@ -507,7 +523,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
donationFragment.cancelDeletionMode();
} else {
super.onBackPressed();
setupToolbar();
setupToolbar(null);
}
}
}

+ 2
- 4
app/src/main/java/fr/mobdev/blooddonation/fragment/InformationFragment.java View File

@@ -149,16 +149,14 @@ public class InformationFragment extends Fragment {
majCView.isChecked(), majEView.isChecked(),
minCView.isChecked(), minEView.isChecked(),
kView.isChecked());
informationListener.onValidate();
informationListener.onValidate(!modify);
}
});
// TODO HIDE keyboard
// getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
return view;
}

public interface InformationListener {
void onValidate();
void onValidate(boolean isFirstTime);
}

}

Loading…
Cancel
Save