Fix for new Config editor on Amazon Devices

This commit is contained in:
Chris 2019-11-26 01:31:06 -05:00
parent e1636754fd
commit eaf487b54c
1 changed files with 50 additions and 27 deletions

View File

@ -1,14 +1,19 @@
package com.MartyrPher.smapiandroidinstaller; package com.MartyrPher.smapiandroidinstaller;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import java.io.File;
import java.io.FileOutputStream;
/** /**
* Fragment that shows the Install Button * Fragment that shows the Install Button
*/ */
@ -36,38 +41,56 @@ public class InstallFragment extends Fragment {
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
{ {
//Start button, one click install. Can't beat it. try
final Button start_button = view.findViewById(R.id.start_button); {
start_button.setOnClickListener(new View.OnClickListener() { //Start button, one click install. Can't beat it.
@Override final Button start_button = view.findViewById(R.id.start_button);
public void onClick(View v) { start_button.setOnClickListener(new View.OnClickListener() {
start_button.setBackgroundColor(getResources().getColor(R.color.colorAccent)); @Override
public void onClick(View v) {
start_button.setBackgroundColor(getResources().getColor(R.color.colorAccent));
//Did the user give permission to storage //Did the user give permission to storage
if (MainActivity.mHasPermissions) if (MainActivity.mHasPermissions)
{
boolean[] foundGame;
ApkExtractor apkExtractor = new ApkExtractor(getActivity());
//Did it find the game.
foundGame = apkExtractor.checkForInstallOrUpgrade();
if((foundGame[0] || foundGame[1]))
{ {
//Start the task boolean[] foundGame;
BackgroundTask backgroundTask = new BackgroundTask(getActivity(), apkExtractor, foundGame[0]); ApkExtractor apkExtractor = new ApkExtractor(getActivity());
backgroundTask.execute();
}
else
{
//Show the dialog saying that the game can't be found
DialogFrag.showDialog(getActivity(), R.string.cant_find, 1);
start_button.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
}
//Did it find the game.
foundGame = apkExtractor.checkForInstallOrUpgrade();
if((foundGame[0] || foundGame[1]))
{
//Start the task
BackgroundTask backgroundTask = new BackgroundTask(getActivity(), apkExtractor, foundGame[0]);
backgroundTask.execute();
}
else
{
//Show the dialog saying that the game can't be found
DialogFrag.showDialog(getActivity(), R.string.cant_find, 1);
start_button.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
}
}
} }
});
}
catch (Exception e)
{
//Try to log a crash in onCreate()
File logFile = new File(Environment.getExternalStorageDirectory() + "/SMAPI Installer/crash.txt");
try {
FileOutputStream stream = new FileOutputStream(logFile);
stream.write(e.getMessage().getBytes());
stream.close();
} }
}); catch(Exception er)
{
Log.e("InstallFrag", er.toString());
}
}
} }
} }