Search in sources :

Example 1 with IGiuaAppFragment

use of com.giua.app.IGiuaAppFragment in project Giua-App by Giua-app.

the class DrawerActivity method onBackPressed.

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen()) {
        mDrawer.closeDrawer();
        return;
    }
    Fragment fragment = getSupportFragmentManager().getFragments().get(0);
    if (// Se il fragment corrente ha un tag ed è una schermata implementata
    fragment.getTag() != null && !fragment.getTag().equals("FRAGMENT_NOT_IMPLEMENTED"))
        if (// Chiama il metodo onBackPressed e se la chiamata viene gestita (ritorna true) allora finisci
        ((IGiuaAppFragment) fragment).onBackPressed())
            return;
    if (!toolbar.getTitle().toString().contains("Home")) {
        // Se non sei nella home vacci
        mDrawer.setSelection(0, false);
        myFragmentManager.changeFragment(R.id.nav_home);
    } else {
        // Vai alla home del telefono se sei già nella home dell'app
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IGiuaAppFragment(com.giua.app.IGiuaAppFragment) Fragment(androidx.fragment.app.Fragment)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Fragment (androidx.fragment.app.Fragment)1 IGiuaAppFragment (com.giua.app.IGiuaAppFragment)1