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;
import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
package com.topjohnwu.magisk;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
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.view.LayoutInflater;
import android.view.View;

View File

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

View File

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

View File

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