Force reload modules, added view if modules are not found, show progress dialog when granting root

This commit is contained in:
dvdandroid 2016-08-23 18:28:27 +02:00
parent e18f4c843a
commit 91c6ae229e
7 changed files with 96 additions and 6 deletions

View File

@ -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) {

View File

@ -178,4 +178,8 @@ public class MagiskFragment extends Fragment {
}
}
}
public void onRootGranted() {
updateStatus();
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}
}

View File

@ -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>

View 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>

View File

@ -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>