mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 23:59:21 -04:00
Refactor CrashFragment.java
This commit is contained in:
parent
668b49eeb8
commit
9705b01bb3
@ -2,7 +2,10 @@ package net.kdt.pojavlaunch.fragments;
|
|||||||
|
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -11,80 +14,76 @@ import net.kdt.pojavlaunch.*;
|
|||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
public class CrashFragment extends Fragment
|
public class CrashFragment extends Fragment {
|
||||||
{
|
public static String LAST_CRASH_FILE = Tools.DIR_DATA + "/lastcrash.txt";
|
||||||
public static String lastCrashFile = Tools.DIR_DATA + "/lastcrash.txt";
|
|
||||||
|
|
||||||
private String crashContent;
|
|
||||||
private TextView crashView;
|
|
||||||
|
|
||||||
public boolean resetCrashLog = false;
|
|
||||||
|
|
||||||
public static boolean isNewCrash(File crashLog) throws Exception {
|
|
||||||
String content = Tools.read(crashLog.getAbsolutePath());
|
|
||||||
return crashLog != null && content.startsWith("---- Minecraft Crash Report ----");
|
|
||||||
}
|
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreateView(inflater, container, savedInstanceState);
|
|
||||||
View view = inflater.inflate(R.layout.lmaintab_crashlog, container, false);
|
|
||||||
|
|
||||||
return view;
|
private TextView mCrashView;
|
||||||
}
|
public boolean mResetCrashLog = false;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle b)
|
|
||||||
{
|
|
||||||
super.onActivityCreated(b);
|
|
||||||
|
|
||||||
crashView = (TextView) getView().findViewById(R.id.lmaintabconsoleLogCrashTextView);
|
|
||||||
crashView.setTypeface(Typeface.MONOSPACE);
|
|
||||||
crashView.setHint(this.getText(R.string.main_nocrash));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume()
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
{
|
super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
return inflater.inflate(R.layout.lmaintab_crashlog, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
mCrashView = (TextView) getView().findViewById(R.id.lmaintabconsoleLogCrashTextView);
|
||||||
|
mCrashView.setTypeface(Typeface.MONOSPACE);
|
||||||
|
mCrashView.setHint(this.getText(R.string.main_nocrash));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume(){
|
||||||
super.onResume();
|
super.onResume();
|
||||||
refreshCrashFile();
|
refreshCrashFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshCrashFile()
|
private void refreshCrashFile() {
|
||||||
{
|
// Default text
|
||||||
|
mCrashView.setText("");
|
||||||
|
setLastCrash("");
|
||||||
|
|
||||||
|
if(mResetCrashLog) return;
|
||||||
|
|
||||||
|
File crashLog = Tools.lastFileModified(Tools.DIR_HOME_CRASH);
|
||||||
|
String lastCrash = getLastCrash();
|
||||||
|
String crashContent;
|
||||||
try {
|
try {
|
||||||
if(!resetCrashLog){
|
if (isNewCrash(crashLog)) {
|
||||||
File crashLog = Tools.lastFileModified(Tools.DIR_HOME_CRASH);
|
crashContent = Tools.read(crashLog.getAbsolutePath());
|
||||||
String lastCrash = getLastCrash();
|
Tools.write(crashLog.getAbsolutePath(), "\n" + crashContent);
|
||||||
if (isNewCrash(crashLog)) {
|
setLastCrash(crashLog.getAbsolutePath());
|
||||||
crashContent = Tools.read(crashLog.getAbsolutePath());
|
mCrashView.setText(crashContent);
|
||||||
Tools.write(crashLog.getAbsolutePath(), "\n" + crashContent);
|
} else if(!lastCrash.isEmpty()) {
|
||||||
setLastCrash(crashLog.getAbsolutePath());
|
crashContent = Tools.read(lastCrash);
|
||||||
crashView.setText(crashContent);
|
mCrashView.setText(crashContent);
|
||||||
} else if(!lastCrash.isEmpty()) {
|
}
|
||||||
crashContent = Tools.read(lastCrash);
|
}catch (IOException ioException){
|
||||||
crashView.setText(crashContent);
|
Log.e("CrashFragment", ioException.toString());
|
||||||
} else throw new Exception();
|
|
||||||
} else throw new Exception();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Can't find crash or no NEW crashes
|
|
||||||
crashView.setText(""/*Log.getStackTraceString(e)*/);
|
|
||||||
setLastCrash("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastCrash(String newValue) {
|
private static boolean isNewCrash(File crashLog) throws IOException {
|
||||||
|
String content = Tools.read(crashLog.getAbsolutePath());
|
||||||
|
return crashLog != null && content.startsWith("---- Minecraft Crash Report ----");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setLastCrash(String newValue) {
|
||||||
try {
|
try {
|
||||||
Tools.write(lastCrashFile, newValue);
|
Tools.write(LAST_CRASH_FILE, newValue);
|
||||||
} catch (Throwable th) {
|
} catch (IOException ioException) {
|
||||||
throw new RuntimeException(th);
|
throw new RuntimeException(ioException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastCrash() {
|
private String getLastCrash() {
|
||||||
try {
|
try {
|
||||||
return Tools.read(lastCrashFile);
|
return Tools.read(LAST_CRASH_FILE);
|
||||||
} catch (Throwable th) {
|
} catch (IOException ioException) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user