[app] Fix NPE (#1453)
This commit is contained in:
parent
005692f271
commit
0af0f52072
|
|
@ -34,7 +34,9 @@ import com.google.android.material.snackbar.Snackbar;
|
|||
import org.lsposed.manager.App;
|
||||
import org.lsposed.manager.R;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
public class BaseFragment extends Fragment {
|
||||
public void navigateUp() {
|
||||
|
|
@ -70,8 +72,12 @@ public class BaseFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
public Future<?> runAsync(Runnable runnable) {
|
||||
return App.getExecutorService().submit(runnable);
|
||||
public void runAsync(Runnable runnable) {
|
||||
App.getExecutorService().submit(runnable);
|
||||
}
|
||||
|
||||
public <T> Future<T> runAsync(Callable<T> callable) {
|
||||
return App.getExecutorService().submit(callable);
|
||||
}
|
||||
|
||||
public void runOnUiThread(Runnable runnable) {
|
||||
|
|
@ -81,6 +87,17 @@ public class BaseFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
public <T> Future<T> runOnUiThread(Callable<T> callable) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null && !activity.isFinishing()) {
|
||||
var task = new FutureTask<>(callable);
|
||||
activity.runOnUiThread(task);
|
||||
return task;
|
||||
} else {
|
||||
return new FutureTask<>(() -> null);
|
||||
}
|
||||
}
|
||||
|
||||
public void showHint(@StringRes int res, boolean lengthShort, @StringRes int actionRes, View.OnClickListener action) {
|
||||
showHint(getString(res), lengthShort, getString(actionRes), action);
|
||||
}
|
||||
|
|
@ -105,4 +122,5 @@ public class BaseFragment extends Fragment {
|
|||
}
|
||||
Toast.makeText(requireContext(), str, lengthShort ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import androidx.core.text.HtmlCompat;
|
|||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.google.android.material.color.MaterialColors;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.lsposed.manager.BuildConfig;
|
||||
import org.lsposed.manager.ConfigManager;
|
||||
|
|
@ -211,7 +210,7 @@ public class HomeFragment extends BaseFragment implements RepoLoader.RepoListene
|
|||
}
|
||||
);
|
||||
runOnUiThread(() -> {
|
||||
if (count[0] > 0) {
|
||||
if (count[0] > 0 && binding != null) {
|
||||
binding.downloadSummary.setText(getResources().getQuantityString(R.plurals.module_repo_upgradable, count[0], count[0]));
|
||||
} else {
|
||||
onThrowable(null);
|
||||
|
|
@ -221,7 +220,10 @@ public class HomeFragment extends BaseFragment implements RepoLoader.RepoListene
|
|||
|
||||
@Override
|
||||
public void onThrowable(Throwable t) {
|
||||
runOnUiThread(() -> binding.downloadSummary.setText(getResources().getString(R.string.module_repo_up_to_date)));
|
||||
runOnUiThread(() -> {
|
||||
if (binding != null)
|
||||
binding.downloadSummary.setText(getResources().getString(R.string.module_repo_up_to_date));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -258,7 +260,10 @@ public class HomeFragment extends BaseFragment implements RepoLoader.RepoListene
|
|||
}
|
||||
|
||||
private void setModulesSummary(int moduleCount) {
|
||||
runOnUiThread(() -> binding.modulesSummary.setText(moduleCount == -1 ? getString(R.string.loading) : getResources().getQuantityString(R.plurals.modules_enabled_count, moduleCount, moduleCount)));
|
||||
runOnUiThread(() -> {
|
||||
if (binding != null)
|
||||
binding.modulesSummary.setText(moduleCount == -1 ? getString(R.string.loading) : getResources().getQuantityString(R.plurals.modules_enabled_count, moduleCount, moduleCount));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -236,8 +236,10 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
|
|||
private void updateModuleSummary() {
|
||||
var moduleCount = moduleUtil.getEnabledModulesCount();
|
||||
runOnUiThread(() -> {
|
||||
binding.toolbar.setSubtitle(moduleCount == -1 ? getString(R.string.loading) : getResources().getQuantityString(R.plurals.modules_enabled_count, moduleCount, moduleCount));
|
||||
binding.toolbarLayout.setSubtitle(binding.toolbar.getSubtitle());
|
||||
if (binding != null) {
|
||||
binding.toolbar.setSubtitle(moduleCount == -1 ? getString(R.string.loading) : getResources().getQuantityString(R.plurals.modules_enabled_count, moduleCount, moduleCount));
|
||||
binding.toolbarLayout.setSubtitle(binding.toolbar.getSubtitle());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,14 +152,16 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
|
|||
count[0] = -1;
|
||||
}
|
||||
runOnUiThread(() -> {
|
||||
if (count[0] > 0) {
|
||||
binding.toolbar.setSubtitle(getResources().getQuantityString(R.plurals.module_repo_upgradable, count[0], count[0]));
|
||||
} else if (count[0] == 0) {
|
||||
binding.toolbar.setSubtitle(getResources().getString(R.string.module_repo_up_to_date));
|
||||
} else {
|
||||
binding.toolbar.setSubtitle(getResources().getString(R.string.loading));
|
||||
if (binding != null) {
|
||||
if (count[0] > 0) {
|
||||
binding.toolbar.setSubtitle(getResources().getQuantityString(R.plurals.module_repo_upgradable, count[0], count[0]));
|
||||
} else if (count[0] == 0) {
|
||||
binding.toolbar.setSubtitle(getResources().getString(R.string.module_repo_up_to_date));
|
||||
} else {
|
||||
binding.toolbar.setSubtitle(getResources().getString(R.string.loading));
|
||||
}
|
||||
binding.toolbarLayout.setSubtitle(binding.toolbar.getSubtitle());
|
||||
}
|
||||
binding.toolbarLayout.setSubtitle(binding.toolbar.getSubtitle());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue