|
|
|
@ -18,6 +18,16 @@
|
|
|
|
|
|
|
|
|
|
package fr.mobdev.blooddonation.activity;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
|
import androidx.core.view.GravityCompat;
|
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout;
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
|
import fr.mobdev.blooddonation.Database;
|
|
|
|
|
import fr.mobdev.blooddonation.R;
|
|
|
|
|
import fr.mobdev.blooddonation.dialog.InformationDialog;
|
|
|
|
@ -35,9 +45,6 @@ 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;
|
|
|
|
|
import android.app.FragmentTransaction;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
@ -48,15 +55,6 @@ import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
import android.provider.Settings;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
import android.support.design.widget.NavigationView;
|
|
|
|
|
import android.support.design.widget.Snackbar;
|
|
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
@ -66,6 +64,8 @@ import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
import android.widget.PopupMenu;
|
|
|
|
|
|
|
|
|
|
import com.google.android.material.navigation.NavigationView;
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -94,14 +94,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.history_toolbar);
|
|
|
|
|
Toolbar toolbar = findViewById(R.id.history_toolbar);
|
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
|
|
|
|
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
|
|
|
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
|
|
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
|
DrawerLayout mDrawerLayout = findViewById(R.id.drawer_layout);
|
|
|
|
|
mDrawerToggle = new ActionBarDrawerToggle(
|
|
|
|
|
this, /* host Activity */
|
|
|
|
|
mDrawerLayout, /* DrawerLayout object */
|
|
|
|
@ -125,7 +125,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
assert actionBar != null;
|
|
|
|
|
getFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
|
|
|
|
|
getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
|
|
|
|
|
public void onBackStackChanged() {
|
|
|
|
|
setupToolbar(null);
|
|
|
|
|
}
|
|
|
|
@ -142,7 +142,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull final String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
if(requestCode == 1 && grantResults.length == 2 && (grantResults[0] == PackageManager.PERMISSION_GRANTED || grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
Fragment frag = manager.findFragmentById(R.id.fragment_container);
|
|
|
|
|
if(frag instanceof MapsFragment) {
|
|
|
|
|
((MapsFragment)frag).startUpdateLocations();
|
|
|
|
@ -158,7 +158,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
barWrite.setAction(R.string.retry, new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
Fragment fragment = manager.findFragmentById(R.id.fragment_container);
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
if(!shouldShowRequestPermissionRationale(permissions[0])) {
|
|
|
|
@ -202,7 +202,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
assert actionBar != null;
|
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
actionBar.setHomeButtonEnabled(true);
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
Fragment maps = MapsFragment.newInstance(postCodeUpdateListener);
|
|
|
|
|
FragmentTransaction transaction = manager.beginTransaction();
|
|
|
|
|
transaction.replace(R.id.fragment_container,maps);
|
|
|
|
@ -211,7 +211,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showEditInformation(boolean modify) {
|
|
|
|
|
final FragmentManager manager = getFragmentManager();
|
|
|
|
|
final FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
|
|
Fragment information = InformationFragment.newInstance(modify, new InformationFragment.InformationListener() {
|
|
|
|
|
@Override
|
|
|
|
@ -224,6 +224,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
View view = getCurrentFocus();
|
|
|
|
|
if(view == null)
|
|
|
|
|
view = new View(MainActivity.this);
|
|
|
|
|
if(inputMethodManager == null)
|
|
|
|
|
return;
|
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(),0);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -236,7 +238,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showAbout() {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
|
|
Fragment about = AboutFragment.newInstance(new AboutFragment.OnLicenceClickListener() {
|
|
|
|
|
@Override
|
|
|
|
@ -252,7 +254,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showDonation() {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
|
|
Fragment donation = DonationFragment.newInstance(new DonationFragment.OnDeletionModeListener() {
|
|
|
|
|
@Override
|
|
|
|
@ -278,7 +280,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showDonationInfo() {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
|
|
Fragment donationInfo = new DonationInfoFragment();
|
|
|
|
|
FragmentTransaction transaction = manager.beginTransaction();
|
|
|
|
@ -289,7 +291,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showLicence() {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
|
|
Fragment licenceFragment = new LicencesFragment();
|
|
|
|
|
FragmentTransaction transaction = manager.beginTransaction();
|
|
|
|
@ -300,7 +302,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showNotifications() {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
|
|
Fragment notifications = new NotificationFragment();
|
|
|
|
|
FragmentTransaction transaction = manager.beginTransaction();
|
|
|
|
@ -311,7 +313,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showPrefs() {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
Fragment prefs = PrefFragment.newInstance(new PrefFragment.OnEditPersonnalInfoListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onEditPesonnalInfoClick() {
|
|
|
|
@ -327,7 +329,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
|
|
|
|
|
void setupToolbar(Fragment frag) {
|
|
|
|
|
if (frag == null) {
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
frag = manager.findFragmentById(R.id.fragment_container);
|
|
|
|
|
}
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
@ -409,7 +411,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@ -472,7 +474,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
args.putLong("siteId", siteId);
|
|
|
|
|
InformationDialog dialog = new InformationDialog();
|
|
|
|
|
dialog.setArguments(args);
|
|
|
|
|
dialog.show(getFragmentManager(), "information dialog");
|
|
|
|
|
dialog.show(getSupportFragmentManager(), "information dialog");
|
|
|
|
|
notifications.remove(id);
|
|
|
|
|
List<Long> notificationsToRemove = new ArrayList<>();
|
|
|
|
|
notificationsToRemove.add(siteId);
|
|
|
|
@ -501,7 +503,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
if (mDrawerToggle.onOptionsItemSelected(item)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
DonationFragment donationFragment;
|
|
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
@ -568,14 +570,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|
|
|
|
PostDonationDialog dialog = new PostDonationDialog();
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
bundle.putInt("depId", postCode);
|
|
|
|
|
|
|
|
|
|
dialog.setArguments(bundle);
|
|
|
|
|
dialog.show(getFragmentManager(), "post donation phone number");
|
|
|
|
|
dialog.show(getSupportFragmentManager(), "post donation phone number");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
|
FragmentManager manager = getFragmentManager();
|
|
|
|
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
|
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
|
|
Fragment frag = manager.findFragmentById(R.id.fragment_container);
|
|
|
|
|
DonationFragment donationFragment = null;
|
|
|
|
|
if (frag instanceof DonationFragment)
|
|
|
|
|