2016-08-21 13:29:42 +00:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
2016-08-27 19:52:03 +00:00
|
|
|
import android.Manifest;
|
2016-08-23 15:02:32 +00:00
|
|
|
import android.content.Intent;
|
2016-09-08 19:47:04 +00:00
|
|
|
import android.content.SharedPreferences;
|
2016-08-27 19:52:03 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2016-09-17 18:32:08 +00:00
|
|
|
import android.os.AsyncTask;
|
2016-08-21 15:42:42 +00:00
|
|
|
import android.os.Build;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2016-08-31 21:52:42 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2016-09-15 21:59:34 +00:00
|
|
|
import android.provider.Settings;
|
2016-08-21 15:21:37 +00:00
|
|
|
import android.support.annotation.IdRes;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.design.widget.NavigationView;
|
2016-08-27 19:52:03 +00:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2016-08-24 21:58:15 +00:00
|
|
|
|
2016-09-11 18:36:58 +00:00
|
|
|
import com.topjohnwu.magisk.module.RepoHelper;
|
2016-08-28 22:35:07 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
2016-08-27 19:52:03 +00:00
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
|
|
|
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
|
|
|
|
|
|
|
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
2016-08-25 12:59:07 +00:00
|
|
|
|
2016-08-23 09:39:18 +00:00
|
|
|
private final Handler mDrawerHandler = new Handler();
|
2016-08-25 09:04:56 +00:00
|
|
|
|
2016-09-16 04:46:10 +00:00
|
|
|
@BindView(R.id.toolbar)
|
|
|
|
Toolbar toolbar;
|
|
|
|
@BindView(R.id.drawer_layout)
|
|
|
|
DrawerLayout drawer;
|
|
|
|
@BindView(R.id.nav_view)
|
|
|
|
NavigationView navigationView;
|
2016-08-21 13:29:42 +00:00
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
@IdRes
|
2016-08-23 09:39:18 +00:00
|
|
|
private int mSelectedId = R.id.magisk;
|
2016-08-22 21:18:28 +00:00
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_welcome);
|
|
|
|
ButterKnife.bind(this);
|
2016-08-23 16:28:27 +00:00
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
// Startups
|
2016-09-15 21:59:34 +00:00
|
|
|
PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false);
|
2016-09-19 07:42:20 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
if (prefs.contains("autoRootEnable")) {
|
|
|
|
if (prefs.getBoolean("autoRootEnable",false)) {
|
|
|
|
if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) {
|
|
|
|
Intent myIntent = new Intent(getApplication(), MonitorService.class);
|
|
|
|
getApplication().startService(myIntent);
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 21:59:34 +00:00
|
|
|
}
|
2016-08-28 22:35:07 +00:00
|
|
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|
|
|
|
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
|
|
|
}
|
2016-09-19 06:46:07 +00:00
|
|
|
|
2016-09-15 21:59:34 +00:00
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
new Utils.Initialize(this).execute();
|
|
|
|
new Utils.CheckUpdates(this).execute();
|
2016-09-11 18:36:58 +00:00
|
|
|
RepoHelper.TaskDelegate delegate = result -> {
|
|
|
|
//Do a thing here when we get a result we want
|
|
|
|
};
|
2016-09-17 18:32:08 +00:00
|
|
|
new Utils.LoadModules(this).execute();
|
2016-09-16 04:46:10 +00:00
|
|
|
new Utils.LoadRepos(this, true, delegate).execute();
|
2016-09-17 18:32:08 +00:00
|
|
|
new Utils.LoadRepos(this, !prefs.contains("hasCachedRepos"), delegate).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2016-09-19 06:46:07 +00:00
|
|
|
new Utils.LoadModules(getApplication()).execute();
|
2016-09-16 04:46:10 +00:00
|
|
|
new Utils.LoadRepos(this, false, delegate).execute();
|
2016-09-11 18:36:58 +00:00
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
|
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
|
|
|
|
@Override
|
|
|
|
public void onDrawerOpened(View drawerView) {
|
|
|
|
super.onDrawerOpened(drawerView);
|
|
|
|
super.onDrawerSlide(drawerView, 0); // this disables the arrow @ completed state
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDrawerSlide(View drawerView, float slideOffset) {
|
|
|
|
super.onDrawerSlide(drawerView, 0); // this disables the animation
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
drawer.addDrawerListener(toggle);
|
2016-08-21 13:29:42 +00:00
|
|
|
toggle.syncState();
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
//noinspection ResourceType
|
|
|
|
mSelectedId = savedInstanceState == null ? mSelectedId : savedInstanceState.getInt(SELECTED_ITEM_ID);
|
|
|
|
navigationView.setCheckedItem(mSelectedId);
|
2016-08-21 13:29:42 +00:00
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
if (savedInstanceState == null) {
|
2016-08-21 13:29:42 +00:00
|
|
|
mDrawerHandler.removeCallbacksAndMessages(null);
|
2016-08-27 11:02:41 +00:00
|
|
|
mDrawerHandler.postDelayed(() -> navigate(mSelectedId), 250);
|
2016-08-21 13:29:42 +00:00
|
|
|
}
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
navigationView.setNavigationItemSelectedListener(this);
|
2016-09-15 21:59:34 +00:00
|
|
|
if (getIntent().hasExtra("relaunch")) {
|
|
|
|
navigate(R.id.root);
|
|
|
|
}
|
2016-08-31 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
|
|
|
outState.putInt(SELECTED_ITEM_ID, mSelectedId);
|
2016-08-21 13:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
|
2016-08-21 15:21:37 +00:00
|
|
|
mSelectedId = menuItem.getItemId();
|
2016-08-21 13:29:42 +00:00
|
|
|
mDrawerHandler.removeCallbacksAndMessages(null);
|
2016-08-27 11:02:41 +00:00
|
|
|
mDrawerHandler.postDelayed(() -> navigate(menuItem.getItemId()), 250);
|
2016-08-21 13:29:42 +00:00
|
|
|
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-15 21:59:34 +00:00
|
|
|
|
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
private void navigate(final int itemId) {
|
|
|
|
Fragment navFragment = null;
|
2016-08-23 16:28:27 +00:00
|
|
|
String tag = "";
|
2016-08-21 13:29:42 +00:00
|
|
|
switch (itemId) {
|
2016-08-23 09:39:18 +00:00
|
|
|
case R.id.magisk:
|
|
|
|
setTitle(R.string.magisk);
|
2016-08-23 16:28:27 +00:00
|
|
|
tag = "magisk";
|
2016-08-23 09:39:18 +00:00
|
|
|
navFragment = new MagiskFragment();
|
|
|
|
break;
|
2016-08-26 10:45:35 +00:00
|
|
|
case R.id.root:
|
|
|
|
setTitle(R.string.root);
|
|
|
|
tag = "root";
|
|
|
|
navFragment = new RootFragment();
|
|
|
|
break;
|
2016-09-15 21:59:34 +00:00
|
|
|
case R.id.autoroot:
|
|
|
|
setTitle(R.string.auto_root);
|
|
|
|
tag = "ic_autoroot";
|
|
|
|
navFragment = new AutoRootFragment();
|
|
|
|
break;
|
2016-08-21 13:29:42 +00:00
|
|
|
case R.id.modules:
|
|
|
|
setTitle(R.string.modules);
|
2016-08-23 16:28:27 +00:00
|
|
|
tag = "modules";
|
2016-08-21 13:29:42 +00:00
|
|
|
navFragment = new ModulesFragment();
|
|
|
|
break;
|
2016-09-11 18:36:58 +00:00
|
|
|
case R.id.downloads:
|
|
|
|
setTitle(R.string.downloads);
|
|
|
|
tag = "downloads";
|
|
|
|
navFragment = new ReposFragment();
|
|
|
|
break;
|
2016-08-21 13:29:42 +00:00
|
|
|
case R.id.log:
|
|
|
|
setTitle(R.string.log);
|
2016-08-23 16:28:27 +00:00
|
|
|
tag = "log";
|
2016-08-21 13:29:42 +00:00
|
|
|
navFragment = new LogFragment();
|
|
|
|
break;
|
2016-08-23 15:02:32 +00:00
|
|
|
case R.id.app_about:
|
|
|
|
startActivity(new Intent(this, AboutActivity.class));
|
|
|
|
return;
|
2016-08-21 13:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (navFragment != null) {
|
|
|
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
|
|
|
transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
|
|
|
|
try {
|
2016-08-21 14:42:50 +00:00
|
|
|
toolbar.setElevation(navFragment instanceof ModulesFragment ? 0 : 10);
|
|
|
|
|
2016-08-23 16:28:27 +00:00
|
|
|
transaction.replace(R.id.content_frame, navFragment, tag).commit();
|
2016-08-21 13:29:42 +00:00
|
|
|
} catch (IllegalStateException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 19:01:35 +00:00
|
|
|
}
|