mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Force reload modules, added view if modules are not found, show progress dialog when granting root
This commit is contained in:
parent
e18f4c843a
commit
91c6ae229e
@ -9,6 +9,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.rv.ItemClickListener;
|
||||
@ -22,6 +23,7 @@ import butterknife.ButterKnife;
|
||||
public abstract class BaseModuleFragment extends Fragment {
|
||||
|
||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||
@BindView(R.id.empty_rv) TextView emptyTv;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ -29,6 +31,13 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
if (listModules().size() == 0) {
|
||||
emptyTv.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
recyclerView.setAdapter(new ModulesAdapter(listModules(), new ItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(View view, int position) {
|
||||
|
@ -178,4 +178,8 @@ public class MagiskFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onRootGranted() {
|
||||
updateStatus();
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
@ -50,14 +53,32 @@ public class ModulesFragment extends Fragment {
|
||||
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
new CheckFolders().execute();
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_modules, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.force_reload:
|
||||
listModules.clear();
|
||||
listModulesCache.clear();
|
||||
|
||||
new CheckFolders().execute();
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public static class NormalModuleFragment extends BaseModuleFragment {
|
||||
|
||||
@Override
|
||||
@ -135,6 +156,9 @@ public class ModulesFragment extends Fragment {
|
||||
super.onPostExecute(v);
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
@ -41,12 +42,14 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_welcome);
|
||||
view = findViewById(R.id.toolbar);
|
||||
ButterKnife.bind(this);
|
||||
view = toolbar;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
initialize = new Init();
|
||||
|
||||
initialize = new Init(this);
|
||||
|
||||
initialize.execute();
|
||||
|
||||
@ -118,17 +121,21 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
|
||||
private void navigate(final int itemId) {
|
||||
Fragment navFragment = null;
|
||||
String tag = "";
|
||||
switch (itemId) {
|
||||
case R.id.magisk:
|
||||
setTitle(R.string.magisk);
|
||||
tag = "magisk";
|
||||
navFragment = new MagiskFragment();
|
||||
break;
|
||||
case R.id.modules:
|
||||
setTitle(R.string.modules);
|
||||
tag = "modules";
|
||||
navFragment = new ModulesFragment();
|
||||
break;
|
||||
case R.id.log:
|
||||
setTitle(R.string.log);
|
||||
tag = "log";
|
||||
navFragment = new LogFragment();
|
||||
break;
|
||||
case R.id.app_about:
|
||||
@ -142,7 +149,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
try {
|
||||
toolbar.setElevation(navFragment instanceof ModulesFragment ? 0 : 10);
|
||||
|
||||
transaction.replace(R.id.content_frame, navFragment).commit();
|
||||
transaction.replace(R.id.content_frame, navFragment, tag).commit();
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
@ -150,6 +157,20 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
|
||||
public static class Init extends AsyncTask<Void, Integer, Void> {
|
||||
|
||||
private final AppCompatActivity activity;
|
||||
private ProgressDialog progress;
|
||||
|
||||
public Init(AppCompatActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
progress = ProgressDialog.show(activity, null, activity.getString(R.string.loading), true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
// Check root access
|
||||
@ -165,9 +186,15 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
protected void onPostExecute(Void v) {
|
||||
super.onPostExecute(v);
|
||||
|
||||
progress.dismiss();
|
||||
|
||||
if (!Utils.rootAccess) {
|
||||
Snackbar.make(view, R.string.no_root_access, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
MagiskFragment fragment = (MagiskFragment) activity.getSupportFragmentManager().findFragmentByTag("magisk");
|
||||
fragment.onRootGranted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,4 +11,16 @@
|
||||
android:layout_height="match_parent"
|
||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_rv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:gravity="center"
|
||||
android:text="@string/no_modules_found"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="italic"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
11
app/src/main/res/menu/menu_modules.xml
Normal file
11
app/src/main/res/menu/menu_modules.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/force_reload"
|
||||
android:icon="@drawable/ic_refresh"
|
||||
android:title="@string/force_reload"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
</menu>
|
@ -46,5 +46,8 @@
|
||||
<string name="app_source_code">Source code</string>
|
||||
<string name="app_translators">App\'s translators</string>
|
||||
<string name="support_thread">Support thread</string>
|
||||
<string name="force_reload">Refresh</string>
|
||||
<string name="no_modules_found">No modules found</string>
|
||||
<string name="loading">Loading…</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user