Update logs

This commit is contained in:
topjohnwu 2017-01-29 16:20:41 +08:00
parent 586015c2ed
commit 49e546919a
6 changed files with 67 additions and 23 deletions

View File

@ -103,9 +103,6 @@ public class MagiskLogFragment extends Fragment {
case R.id.menu_refresh:
new LogManager().read();
return true;
case R.id.menu_send:
new LogManager().send();
return true;
case R.id.menu_save:
new LogManager().save();
return true;

View File

@ -77,6 +77,8 @@ public class SettingsActivity extends AppCompatActivity {
private SharedPreferences prefs;
private PreferenceScreen prefScreen;
private ListPreference suAccess, autoRes, suNotification, requestTimeout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -87,19 +89,12 @@ public class SettingsActivity extends AppCompatActivity {
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
ListPreference suAccess = (ListPreference) findPreference("su_access");
ListPreference autoRes = (ListPreference) findPreference("su_auto_response");
ListPreference requestTimeout = (ListPreference) findPreference("su_request_timeout");
ListPreference suNotification = (ListPreference) findPreference("su_notification");
suAccess = (ListPreference) findPreference("su_access");
autoRes = (ListPreference) findPreference("su_auto_response");
requestTimeout = (ListPreference) findPreference("su_request_timeout");
suNotification = (ListPreference) findPreference("su_notification");
suAccess.setSummary(getResources()
.getStringArray(R.array.su_access)[Utils.getPrefsInt(prefs, "su_access", 3)]);
autoRes.setSummary(getResources()
.getStringArray(R.array.auto_response)[Utils.getPrefsInt(prefs, "su_auto_response", 0)]);
suNotification.setSummary(getResources()
.getStringArray(R.array.su_notification)[Utils.getPrefsInt(prefs, "su_notification", 1)]);
requestTimeout.setSummary(
getString(R.string.request_timeout_summary, prefs.getString("su_request_timeout", "10")));
setSummary();
CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
CheckBoxPreference magiskhidePreference = (CheckBoxPreference) findPreference("magiskhide");
@ -206,6 +201,8 @@ public class SettingsActivity extends AppCompatActivity {
case "su_access":
Global.Configs.suAccessState = Utils.getPrefsInt(prefs, "su_access", 0);
Shell.su("setprop persist.sys.root_access " + Global.Configs.suAccessState);
suAccess.setSummary(getResources()
.getStringArray(R.array.su_access)[Global.Configs.suAccessState]);
break;
case "su_request_timeout":
Global.Configs.suRequestTimeout = Utils.getPrefsInt(prefs, "su_request_timeout", 10);
@ -223,6 +220,18 @@ public class SettingsActivity extends AppCompatActivity {
Global.Configs.shellLogging = prefs.getBoolean("shell_logging", false);
break;
}
setSummary();
}
private void setSummary() {
suAccess.setSummary(getResources()
.getStringArray(R.array.su_access)[Global.Configs.suAccessState]);
autoRes.setSummary(getResources()
.getStringArray(R.array.auto_response)[Global.Configs.suResponseType]);
suNotification.setSummary(getResources()
.getStringArray(R.array.su_notification)[Global.Configs.suNotificationType]);
requestTimeout.setSummary(
getString(R.string.request_timeout_summary, prefs.getString("su_request_timeout", "10")));
}
}

View File

@ -1,9 +1,13 @@
package com.topjohnwu.magisk;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
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.TextView;
@ -24,6 +28,19 @@ public class SuLogFragment extends Fragment {
@BindView(R.id.recyclerView) RecyclerView recyclerView;
private Unbinder unbinder;
private SuLogDatabaseHelper dbHelper;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_log, menu);
menu.findItem(R.id.menu_save).setVisible(false);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -32,7 +49,14 @@ public class SuLogFragment extends Fragment {
View v = inflater.inflate(R.layout.fragment_su_log, container, false);
unbinder = ButterKnife.bind(this, v);
SuLogDatabaseHelper dbHelper = new SuLogDatabaseHelper(getActivity());
dbHelper = new SuLogDatabaseHelper(getActivity());
updateList();
return v;
}
private void updateList() {
List<SuLogEntry> logs = dbHelper.getLogList();
if (logs.size() == 0) {
@ -43,8 +67,21 @@ public class SuLogFragment extends Fragment {
emptyRv.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
}
return v;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_refresh:
updateList();
return true;
case R.id.menu_clear:
dbHelper.clearLogs();
updateList();
return true;
default:
return true;
}
}
@Override

View File

@ -108,6 +108,7 @@ public class SuLogAdapter {
@Override
public void onBindGroupViewHolder(LogGroupViewHolder holder, int flatPosition, ExpandableGroup group) {
holder.date.setText(group.getTitle());
if (isGroupExpanded(flatPosition)) holder.expand();
}
}

View File

@ -38,6 +38,12 @@ public class SuLogDatabaseHelper extends SQLiteOpenHelper {
db.close();
}
public void clearLogs() {
SQLiteDatabase db = getWritableDatabase();
db.delete(TABLE_NAME, null, null);
db.close();
}
public List<SuLogEntry> getLogList() {
return getLogList(null);
}

View File

@ -8,12 +8,6 @@
android:title="@string/menuSaveToSd"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_send"
android:icon="@drawable/ic_send"
android:title="@string/menuSend"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_clear"
android:icon="@drawable/ic_delete"