mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 05:07:45 +02:00
Start materializing module fragment
This commit is contained in:
121
app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
Normal file
121
app/src/main/java/com/topjohnwu/magisk/WelcomeActivity.java
Normal file
@ -0,0 +1,121 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
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;
|
||||
|
||||
import com.topjohnwu.magisk.ui.LogFragment;
|
||||
import com.topjohnwu.magisk.ui.ModulesFragment;
|
||||
import com.topjohnwu.magisk.ui.RootFragment;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
||||
private final Handler mDrawerHandler = new Handler();
|
||||
|
||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||
@BindView(R.id.drawer_layout) DrawerLayout drawer;
|
||||
@BindView(R.id.nav_view) NavigationView navigationView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_welcome);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
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
|
||||
}
|
||||
};
|
||||
|
||||
drawer.setDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mDrawerHandler.removeCallbacksAndMessages(null);
|
||||
mDrawerHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
navigate(savedInstanceState.getInt(SELECTED_ITEM_ID));
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
|
||||
menuItem.setChecked(true);
|
||||
mDrawerHandler.removeCallbacksAndMessages(null);
|
||||
mDrawerHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
navigate(menuItem.getItemId());
|
||||
}
|
||||
}, 250);
|
||||
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void navigate(final int itemId) {
|
||||
Fragment navFragment = null;
|
||||
switch (itemId) {
|
||||
case R.id.root:
|
||||
setTitle(R.string.root);
|
||||
navFragment = new RootFragment();
|
||||
break;
|
||||
case R.id.modules:
|
||||
setTitle(R.string.modules);
|
||||
navFragment = new ModulesFragment();
|
||||
break;
|
||||
case R.id.log:
|
||||
setTitle(R.string.log);
|
||||
navFragment = new LogFragment();
|
||||
break;
|
||||
}
|
||||
|
||||
if (navFragment != null) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
|
||||
try {
|
||||
transaction.replace(R.id.content_frame, navFragment).commit();
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ public class Module {
|
||||
|
||||
private String mName;
|
||||
private String mVersion;
|
||||
private int mVersionCode;
|
||||
private String mDescription;
|
||||
|
||||
public Module(File file) {
|
||||
@ -36,10 +35,6 @@ public class Module {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return mVersionCode;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return mVersion;
|
||||
}
|
||||
@ -70,9 +65,6 @@ public class Module {
|
||||
case "version":
|
||||
mVersion = value;
|
||||
break;
|
||||
case "versionCode":
|
||||
mVersionCode = Integer.parseInt(value);
|
||||
break;
|
||||
case "description":
|
||||
mDescription = value;
|
||||
break;
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.topjohnwu.magisk.rv;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
@ -13,48 +11,60 @@ import com.topjohnwu.magisk.model.Module;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ModulesAdapter extends ArrayAdapter<Module> {
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public ModulesAdapter(Context context, int resource, List<Module> modules) {
|
||||
super(context, resource, modules);
|
||||
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
|
||||
|
||||
private final List<Module> mList;
|
||||
|
||||
public ModulesAdapter(List<Module> mList) {
|
||||
this.mList = mList;
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder vh;
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row, parent, false);
|
||||
/*FIXME
|
||||
final ViewHolder viewHolder = new ViewHolder(view);
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.onItemClick(viewHolder.getAdapterPosition());
|
||||
}
|
||||
});*/
|
||||
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.row, null);
|
||||
|
||||
vh = new ViewHolder();
|
||||
vh.name = (TextView) convertView.findViewById(R.id.name);
|
||||
vh.version = (TextView) convertView.findViewById(R.id.version);
|
||||
vh.versionCode = (TextView) convertView.findViewById(R.id.versionCode);
|
||||
vh.description = (TextView) convertView.findViewById(R.id.description);
|
||||
vh.cache = (TextView) convertView.findViewById(R.id.cache);
|
||||
|
||||
convertView.setTag(vh);
|
||||
} else {
|
||||
vh = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
Module module = getItem(position);
|
||||
vh.name.setText("name= " + module.getName());
|
||||
vh.version.setText("version= " + module.getVersion());
|
||||
vh.versionCode.setText("versioncode= " + module.getVersionCode());
|
||||
vh.description.setText("description= " + module.getDescription());
|
||||
vh.cache.setText("is from cache= " + module.isCache());
|
||||
|
||||
return convertView;
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
public TextView name;
|
||||
public TextView version;
|
||||
public TextView versionCode;
|
||||
public TextView description;
|
||||
public TextView cache;
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
Module module = mList.get(position);
|
||||
|
||||
holder.title.setText(module.getName());
|
||||
holder.versionName.setText(module.getVersion());
|
||||
holder.description.setText(module.getDescription());
|
||||
|
||||
//FIXME
|
||||
|
||||
//holder.cache.setText("" + module.isCache());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.title) TextView title;
|
||||
@BindView(R.id.version_name) TextView versionName;
|
||||
@BindView(R.id.description) TextView description;
|
||||
//@BindView(R.id.cache) TextView cache;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.topjohnwu.magisk.ui;
|
||||
|
||||
public class LogFragment extends android.support.v4.app.Fragment {
|
||||
// private static final String MAGISK_LOG = "/cache/magisk.log";
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.topjohnwu.magisk.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -35,17 +35,23 @@ public class MainActivity extends Activity {
|
||||
suPath = executeCommand("getprop magisk.supath");
|
||||
updateStatus();
|
||||
|
||||
rootToggle.setOnCheckedChangeListener((view, checked) -> {
|
||||
executeCommand(checked ? "setprop magisk.root 1" : "setprop magisk.root 0");
|
||||
updateStatus();
|
||||
rootToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
executeCommand(b ? "setprop magisk.root 1" : "setprop magisk.root 0");
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
|
||||
selinuxToggle.setOnCheckedChangeListener((view, checked) -> {
|
||||
executeCommand(checked ? "setenforce 1" : "setenforce 0");
|
||||
updateStatus();
|
||||
selinuxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
executeCommand(b ? "setenforce 1" : "setenforce 0");
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.modules).setOnClickListener(view -> startActivity(new Intent(this, ModulesActivity.class)));
|
||||
//findViewById(R.id.modules).setOnClickListener(view -> startActivity(new Intent(this, ModulesActivity.class)));
|
||||
}
|
||||
|
||||
private void updateStatus() {
|
||||
|
@ -1,35 +1,45 @@
|
||||
package com.topjohnwu.magisk.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ListView;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.model.Module;
|
||||
import com.topjohnwu.magisk.rv.ModulesAdapter;
|
||||
import com.topjohnwu.magisk.ui.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModulesActivity extends Activity {
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ModulesFragment extends android.support.v4.app.Fragment {
|
||||
|
||||
private static final String MAGISK_PATH = "/magisk";
|
||||
private static final String MAGISK_CACHE_PATH = "/cache/magisk";
|
||||
|
||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||
|
||||
private List<Module> listModules = new ArrayList<>();
|
||||
private ListView mListView;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_modules);
|
||||
|
||||
mListView = (ListView) findViewById(android.R.id.list);
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.modules_fragment, container, false);
|
||||
ButterKnife.bind(this, v);
|
||||
|
||||
new CheckFolders().execute();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private class CheckFolders extends AsyncTask<Void, Integer, Boolean> {
|
||||
@ -40,13 +50,26 @@ public class ModulesActivity extends Activity {
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
progress = ProgressDialog.show(ModulesActivity.this, null, getString(R.string.loading), true, false);
|
||||
progress = ProgressDialog.show(getContext(), null, getString(R.string.loading), true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
File[] magisk = new File(MAGISK_PATH).listFiles(File::isDirectory);
|
||||
File[] magiskCache = new File(MAGISK_CACHE_PATH).listFiles(File::isDirectory);
|
||||
File[] magisk = new File(MAGISK_PATH).listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return file.isDirectory();
|
||||
}
|
||||
});
|
||||
|
||||
Utils.executeCommand("chmod 777 /cache");
|
||||
|
||||
File[] magiskCache = new File(MAGISK_CACHE_PATH).listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return file.isDirectory();
|
||||
}
|
||||
});
|
||||
|
||||
if (magisk != null) {
|
||||
for (File mod : magisk) {
|
||||
@ -83,7 +106,7 @@ public class ModulesActivity extends Activity {
|
||||
|
||||
progress.dismiss();
|
||||
|
||||
mListView.setAdapter(new ModulesAdapter(ModulesActivity.this, R.layout.row, listModules));
|
||||
recyclerView.setAdapter(new ModulesAdapter(listModules));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
package com.topjohnwu.magisk.ui;
|
||||
|
||||
public class RootFragment extends android.support.v4.app.Fragment {
|
||||
}
|
Reference in New Issue
Block a user