Use support library

This commit is contained in:
topjohnwu 2017-01-29 00:20:43 +08:00
parent 9bc0b7f183
commit 4a7e067d1a
11 changed files with 32 additions and 49 deletions

View File

@ -1,10 +1,10 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;

View File

@ -1,9 +1,9 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;

View File

@ -1,9 +1,9 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Fragment;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;

View File

@ -2,7 +2,6 @@ package com.topjohnwu.magisk;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
@ -14,6 +13,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;

View File

@ -1,8 +1,6 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.Manifest; import android.Manifest;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -13,6 +11,8 @@ import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -30,8 +30,6 @@ import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, CallbackHandler.EventListener { implements NavigationView.OnNavigationItemSelectedListener, CallbackHandler.EventListener {
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
private final Handler mDrawerHandler = new Handler(); private final Handler mDrawerHandler = new Handler();
private SharedPreferences prefs; private SharedPreferences prefs;
@ -39,7 +37,6 @@ public class MainActivity extends AppCompatActivity
@BindView(R.id.drawer_layout) DrawerLayout drawer; @BindView(R.id.drawer_layout) DrawerLayout drawer;
@BindView(R.id.nav_view) public NavigationView navigationView; @BindView(R.id.nav_view) public NavigationView navigationView;
private int mSelectedId = R.id.status;
private float toolbarElevation; private float toolbarElevation;
@Override @Override
@ -79,15 +76,11 @@ public class MainActivity extends AppCompatActivity
drawer.addDrawerListener(toggle); drawer.addDrawerListener(toggle);
toggle.syncState(); toggle.syncState();
if (savedInstanceState == null) { navigate(R.id.status);
navigate(mSelectedId, true);
navigationView.setCheckedItem(mSelectedId);
} else {
mSelectedId = savedInstanceState.getInt(SELECTED_ITEM_ID);
}
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
CallbackHandler.register(Global.Events.reloadMainActivity, this); CallbackHandler.register(Global.Events.reloadMainActivity, this);
} }
@Override @Override
@ -112,12 +105,6 @@ public class MainActivity extends AppCompatActivity
super.onDestroy(); super.onDestroy();
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(SELECTED_ITEM_ID, mSelectedId);
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (drawer.isDrawerOpen(navigationView)) { if (drawer.isDrawerOpen(navigationView)) {
@ -129,9 +116,8 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
mSelectedId = menuItem.getItemId();
mDrawerHandler.removeCallbacksAndMessages(null); mDrawerHandler.removeCallbacksAndMessages(null);
mDrawerHandler.postDelayed(() -> navigate(menuItem.getItemId(), false), 250); mDrawerHandler.postDelayed(() -> navigate(menuItem.getItemId()), 250);
drawer.closeDrawer(navigationView); drawer.closeDrawer(navigationView);
return true; return true;
} }
@ -159,29 +145,28 @@ public class MainActivity extends AppCompatActivity
} }
} }
public void navigate(int itemId, boolean now) { public void navigate(int itemId) {
toolbar.setElevation(toolbarElevation);
switch (itemId) { switch (itemId) {
case R.id.status: case R.id.status:
displayFragment(new StatusFragment(), "status", now); displayFragment(new StatusFragment(), "status", true);
break; break;
case R.id.install: case R.id.install:
displayFragment(new InstallFragment(), "install", now); displayFragment(new InstallFragment(), "install", true);
break; break;
case R.id.superuser: case R.id.superuser:
displayFragment(new SuperuserFragment(), "superuser", now); displayFragment(new SuperuserFragment(), "superuser", true);
break; break;
case R.id.modules: case R.id.modules:
displayFragment(new ModulesFragment(), "modules", now); displayFragment(new ModulesFragment(), "modules", true);
break; break;
case R.id.downloads: case R.id.downloads:
displayFragment(new ReposFragment(), "downloads", now); displayFragment(new ReposFragment(), "downloads", true);
break; break;
case R.id.magiskhide: case R.id.magiskhide:
displayFragment(new MagiskHideFragment(), "magiskhide", now); displayFragment(new MagiskHideFragment(), "magiskhide", true);
break; break;
case R.id.log: case R.id.log:
displayFragment(new LogFragment(), "log", now); displayFragment(new LogFragment(), "log", false);
toolbar.setElevation(0); toolbar.setElevation(0);
break; break;
case R.id.settings: case R.id.settings:
@ -193,11 +178,10 @@ public class MainActivity extends AppCompatActivity
} }
} }
private void displayFragment(@NonNull Fragment navFragment, String tag, boolean now) { private void displayFragment(@NonNull Fragment navFragment, String tag, boolean setElevation) {
FragmentTransaction transaction = getFragmentManager().beginTransaction(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (!now) { transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.replace(R.id.content_frame, navFragment, tag).commitNow();
} if (setElevation) toolbar.setElevation(toolbarElevation);
transaction.replace(R.id.content_frame, navFragment, tag).commit();
} }
} }

View File

@ -1,11 +1,11 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;

View File

@ -1,8 +1,8 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;

View File

@ -1,12 +1,12 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;

View File

@ -1,8 +1,7 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;

View File

@ -1,10 +1,9 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Fragment;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;

View File

@ -1,8 +1,9 @@
package com.topjohnwu.magisk.adapters; package com.topjohnwu.magisk.adapters;
import android.app.Fragment;
import android.app.FragmentManager; import android.support.v4.app.Fragment;
import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;