actions are moved to a separate class

This commit is contained in:
Boris Timofeev 2017-08-31 11:07:23 +03:00
parent b267f87a99
commit 3e2f57dbd7
7 changed files with 66 additions and 43 deletions

View file

@ -0,0 +1,35 @@
/*
Copyright (c) 2017 Boris Timofeev
This file is part of UniPatcher.
UniPatcher is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UniPatcher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UniPatcher. If not, see <http://www.gnu.org/licenses/>.
*/
package org.emunix.unipatcher;
public class Action {
public static final int SELECT_ROM_FILE = 1;
public static final int SELECT_PATCH_FILE = 2;
public static final int SELECT_SOURCE_FILE = 3;
public static final int SELECT_MODIFIED_FILE = 4;
public static final int SELECT_HEADER_FILE = 5;
public static final int APPLY_PATCH = 101;
public static final int CREATE_PATCH = 102;
public static final int SMD_FIX_CHECKSUM = 103;
public static final int SNES_ADD_SMC_HEADER = 104;
public static final int SNES_DELETE_SMC_HEADER = 105;
}

View file

@ -29,10 +29,4 @@ public class Globals {
public static void setCmdArgument(String cmdArgument) { public static void setCmdArgument(String cmdArgument) {
Globals.cmdArgument = cmdArgument; Globals.cmdArgument = cmdArgument;
} }
public static final int ACTION_PATCHING = 1;
public static final int ACTION_CREATE_PATCH = 2;
public static final int ACTION_SMD_FIX_CHECKSUM = 3;
public static final int ACTION_SNES_ADD_SMC_HEADER = 4;
public static final int ACTION_SNES_DELETE_SMC_HEADER = 5;
} }

View file

@ -75,19 +75,19 @@ public class WorkerService extends IntentService {
try { try {
int action = intent.getIntExtra("action", 0); int action = intent.getIntExtra("action", 0);
switch (action) { switch (action) {
case Globals.ACTION_PATCHING: case Action.APPLY_PATCH:
actionPatching(intent); actionPatching(intent);
break; break;
case Globals.ACTION_CREATE_PATCH: case Action.CREATE_PATCH:
actionCreatePatch(intent); actionCreatePatch(intent);
break; break;
case Globals.ACTION_SMD_FIX_CHECKSUM: case Action.SMD_FIX_CHECKSUM:
actionSmdFixChecksum(intent); actionSmdFixChecksum(intent);
break; break;
case Globals.ACTION_SNES_ADD_SMC_HEADER: case Action.SNES_ADD_SMC_HEADER:
actionSnesAddSmcHeader(intent); actionSnesAddSmcHeader(intent);
break; break;
case Globals.ACTION_SNES_DELETE_SMC_HEADER: case Action.SNES_DELETE_SMC_HEADER:
actionSnesDeleteSmcHeader(intent); actionSnesDeleteSmcHeader(intent);
break; break;
} }

View file

@ -37,7 +37,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.emunix.unipatcher.Globals; import org.emunix.unipatcher.Action;
import org.emunix.unipatcher.R; import org.emunix.unipatcher.R;
import org.emunix.unipatcher.Settings; import org.emunix.unipatcher.Settings;
import org.emunix.unipatcher.Utils; import org.emunix.unipatcher.Utils;
@ -50,8 +50,6 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL
private static final String LOG_TAG = "org.emunix.unipatcher"; private static final String LOG_TAG = "org.emunix.unipatcher";
private static final int SELECT_SOURCE_FILE = 1;
private static final int SELECT_MODIFIED_FILE = 2;
private TextView sourceNameTextView; private TextView sourceNameTextView;
private TextView modifiedNameTextView; private TextView modifiedNameTextView;
private TextView patchNameTextView; private TextView patchNameTextView;
@ -136,12 +134,12 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL
case R.id.sourceFileCardView: case R.id.sourceFileCardView:
intent.putExtra("title", getString(R.string.file_picker_activity_title_select_source_file)); intent.putExtra("title", getString(R.string.file_picker_activity_title_select_source_file));
intent.putExtra("directory", Settings.getRomDir(getActivity())); intent.putExtra("directory", Settings.getRomDir(getActivity()));
startActivityForResult(intent, SELECT_SOURCE_FILE); startActivityForResult(intent, Action.SELECT_SOURCE_FILE);
break; break;
case R.id.modifiedFileCardView: case R.id.modifiedFileCardView:
intent.putExtra("title", getString(R.string.file_picker_activity_title_select_modified_file)); intent.putExtra("title", getString(R.string.file_picker_activity_title_select_modified_file));
intent.putExtra("directory", Settings.getRomDir(getActivity())); intent.putExtra("directory", Settings.getRomDir(getActivity()));
startActivityForResult(intent, SELECT_MODIFIED_FILE); startActivityForResult(intent, Action.SELECT_MODIFIED_FILE);
break; break;
case R.id.patchFileCardView: case R.id.patchFileCardView:
renamePatchFile(); renamePatchFile();
@ -157,13 +155,13 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL
File fpath = new File(path); File fpath = new File(path);
switch (requestCode) { switch (requestCode) {
case SELECT_SOURCE_FILE: case Action.SELECT_SOURCE_FILE:
sourcePath = path; sourcePath = path;
sourceNameTextView.setVisibility(View.VISIBLE); sourceNameTextView.setVisibility(View.VISIBLE);
sourceNameTextView.setText(fpath.getName()); sourceNameTextView.setText(fpath.getName());
Settings.setLastRomDir(getActivity(), fpath.getParent()); Settings.setLastRomDir(getActivity(), fpath.getParent());
break; break;
case SELECT_MODIFIED_FILE: case Action.SELECT_MODIFIED_FILE:
modifiedPath = path; modifiedPath = path;
modifiedNameTextView.setVisibility(View.VISIBLE); modifiedNameTextView.setVisibility(View.VISIBLE);
modifiedNameTextView.setText(fpath.getName()); modifiedNameTextView.setText(fpath.getName());
@ -198,7 +196,7 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL
} }
Intent intent = new Intent(getActivity(), WorkerService.class); Intent intent = new Intent(getActivity(), WorkerService.class);
intent.putExtra("action", Globals.ACTION_CREATE_PATCH); intent.putExtra("action", Action.CREATE_PATCH);
intent.putExtra("sourcePath", sourcePath); intent.putExtra("sourcePath", sourcePath);
intent.putExtra("modifiedPath", modifiedPath); intent.putExtra("modifiedPath", modifiedPath);
intent.putExtra("patchPath", patchPath); intent.putExtra("patchPath", patchPath);

View file

@ -36,6 +36,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.emunix.unipatcher.Action;
import org.emunix.unipatcher.Globals; import org.emunix.unipatcher.Globals;
import org.emunix.unipatcher.R; import org.emunix.unipatcher.R;
import org.emunix.unipatcher.Settings; import org.emunix.unipatcher.Settings;
@ -49,8 +50,6 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList
private static final String LOG_TAG = "org.emunix.unipatcher"; private static final String LOG_TAG = "org.emunix.unipatcher";
private static final int SELECT_ROM_FILE = 1;
private static final int SELECT_PATCH_FILE = 2;
private TextView romNameTextView; private TextView romNameTextView;
private TextView patchNameTextView; private TextView patchNameTextView;
private TextView outputNameTextView; private TextView outputNameTextView;
@ -147,12 +146,12 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList
case R.id.patchCardView: case R.id.patchCardView:
intent.putExtra("title", getString(R.string.file_picker_activity_title_select_patch)); intent.putExtra("title", getString(R.string.file_picker_activity_title_select_patch));
intent.putExtra("directory", Settings.getPatchDir(getActivity())); intent.putExtra("directory", Settings.getPatchDir(getActivity()));
startActivityForResult(intent, SELECT_PATCH_FILE); startActivityForResult(intent, Action.SELECT_PATCH_FILE);
break; break;
case R.id.romCardView: case R.id.romCardView:
intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom)); intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom));
intent.putExtra("directory", Settings.getRomDir(getActivity())); intent.putExtra("directory", Settings.getRomDir(getActivity()));
startActivityForResult(intent, SELECT_ROM_FILE); startActivityForResult(intent, Action.SELECT_ROM_FILE);
break; break;
case R.id.outputCardView: case R.id.outputCardView:
renameOutputRom(); renameOutputRom();
@ -172,7 +171,7 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList
} }
switch (requestCode) { switch (requestCode) {
case SELECT_ROM_FILE: case Action.SELECT_ROM_FILE:
romPath = path; romPath = path;
romNameTextView.setVisibility(View.VISIBLE); romNameTextView.setVisibility(View.VISIBLE);
romNameTextView.setText(fpath.getName()); romNameTextView.setText(fpath.getName());
@ -180,7 +179,7 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList
outputPath = makeOutputPath(path); outputPath = makeOutputPath(path);
outputNameTextView.setText(new File(outputPath).getName()); outputNameTextView.setText(new File(outputPath).getName());
break; break;
case SELECT_PATCH_FILE: case Action.SELECT_PATCH_FILE:
patchPath = path; patchPath = path;
patchNameTextView.setVisibility(View.VISIBLE); patchNameTextView.setVisibility(View.VISIBLE);
patchNameTextView.setText(fpath.getName()); patchNameTextView.setText(fpath.getName());
@ -214,7 +213,7 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList
} }
Intent intent = new Intent(getActivity(), WorkerService.class); Intent intent = new Intent(getActivity(), WorkerService.class);
intent.putExtra("action", Globals.ACTION_PATCHING); intent.putExtra("action", Action.APPLY_PATCH);
intent.putExtra("romPath", romPath); intent.putExtra("romPath", romPath);
intent.putExtra("patchPath", patchPath); intent.putExtra("patchPath", patchPath);
intent.putExtra("outputPath", outputPath); intent.putExtra("outputPath", outputPath);

View file

@ -31,7 +31,7 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.emunix.unipatcher.Globals; import org.emunix.unipatcher.Action;
import org.emunix.unipatcher.R; import org.emunix.unipatcher.R;
import org.emunix.unipatcher.Settings; import org.emunix.unipatcher.Settings;
import org.emunix.unipatcher.Utils; import org.emunix.unipatcher.Utils;
@ -43,7 +43,6 @@ import java.io.File;
public class SmdFixChecksumFragment extends ActionFragment implements View.OnClickListener { public class SmdFixChecksumFragment extends ActionFragment implements View.OnClickListener {
private static final String LOG_TAG = "org.emunix.unipatcher"; private static final String LOG_TAG = "org.emunix.unipatcher";
private static final int SELECT_ROM_FILE = 1;
private TextView romNameTextView; private TextView romNameTextView;
private TextView fixChecksumInfoTextview; private TextView fixChecksumInfoTextview;
@ -108,7 +107,7 @@ public class SmdFixChecksumFragment extends ActionFragment implements View.OnCli
case R.id.romCardView: case R.id.romCardView:
intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom)); intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom));
intent.putExtra("directory", Settings.getRomDir(getActivity())); intent.putExtra("directory", Settings.getRomDir(getActivity()));
startActivityForResult(intent, SELECT_ROM_FILE); startActivityForResult(intent, Action.SELECT_ROM_FILE);
break; break;
} }
} }
@ -124,7 +123,7 @@ public class SmdFixChecksumFragment extends ActionFragment implements View.OnCli
} }
switch (requestCode) { switch (requestCode) {
case SELECT_ROM_FILE: case Action.SELECT_ROM_FILE:
romPath = path; romPath = path;
romNameTextView.setVisibility(View.VISIBLE); romNameTextView.setVisibility(View.VISIBLE);
romNameTextView.setText(new File(path).getName()); romNameTextView.setText(new File(path).getName());
@ -142,8 +141,8 @@ public class SmdFixChecksumFragment extends ActionFragment implements View.OnCli
} }
Intent intent = new Intent(getActivity(), WorkerService.class); Intent intent = new Intent(getActivity(), WorkerService.class);
intent.putExtra("action", Globals.ACTION_SMD_FIX_CHECKSUM);
intent.putExtra("romPath", romPath); intent.putExtra("romPath", romPath);
intent.putExtra("action", Action.SMD_FIX_CHECKSUM);
getActivity().startService(intent); getActivity().startService(intent);
Toast.makeText(getActivity(), R.string.notify_smd_fix_checksum_started_check_notify, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), R.string.notify_smd_fix_checksum_started_check_notify, Toast.LENGTH_SHORT).show();

View file

@ -31,7 +31,7 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.emunix.unipatcher.Globals; import org.emunix.unipatcher.Action;
import org.emunix.unipatcher.R; import org.emunix.unipatcher.R;
import org.emunix.unipatcher.Settings; import org.emunix.unipatcher.Settings;
import org.emunix.unipatcher.Utils; import org.emunix.unipatcher.Utils;
@ -43,8 +43,6 @@ import java.io.File;
public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClickListener { public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClickListener {
private static final String LOG_TAG = "org.emunix.unipatcher"; private static final String LOG_TAG = "org.emunix.unipatcher";
private static final int SELECT_ROM_FILE = 1;
private static final int SELECT_HEADER_FILE = 2;
private TextView romNameTextView; private TextView romNameTextView;
private TextView headerNameTextView; private TextView headerNameTextView;
@ -104,10 +102,10 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic
romPath = savedInstanceState.getString("romPath"); romPath = savedInstanceState.getString("romPath");
headerPath = savedInstanceState.getString("headerPath"); headerPath = savedInstanceState.getString("headerPath");
action = savedInstanceState.getInt("action"); action = savedInstanceState.getInt("action");
if (action == Globals.ACTION_SNES_ADD_SMC_HEADER) { if (action == Action.SNES_ADD_SMC_HEADER) {
headerInfoTextView.setText(R.string.snes_smc_header_will_be_added); headerInfoTextView.setText(R.string.snes_smc_header_will_be_added);
headerCardView.setVisibility(View.VISIBLE); headerCardView.setVisibility(View.VISIBLE);
} else if (action == Globals.ACTION_SNES_DELETE_SMC_HEADER) { } else if (action == Action.SNES_DELETE_SMC_HEADER) {
headerInfoTextView.setText(R.string.snes_smc_header_will_be_removed); headerInfoTextView.setText(R.string.snes_smc_header_will_be_removed);
headerCardView.setVisibility(View.GONE); headerCardView.setVisibility(View.GONE);
} }
@ -133,11 +131,11 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic
case R.id.romCardView: case R.id.romCardView:
intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom)); intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom));
intent.putExtra("directory", Settings.getRomDir(getActivity())); intent.putExtra("directory", Settings.getRomDir(getActivity()));
startActivityForResult(intent, SELECT_ROM_FILE); startActivityForResult(intent, Action.SELECT_ROM_FILE);
break; break;
case R.id.headerCardView: case R.id.headerCardView:
intent.putExtra("title", getString(R.string.file_picker_activity_title_select_header)); intent.putExtra("title", getString(R.string.file_picker_activity_title_select_header));
startActivityForResult(intent, SELECT_HEADER_FILE); startActivityForResult(intent, Action.SELECT_HEADER_FILE);
break; break;
} }
} }
@ -153,25 +151,25 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic
} }
switch (requestCode) { switch (requestCode) {
case SELECT_ROM_FILE: case Action.SELECT_ROM_FILE:
romPath = path; romPath = path;
romNameTextView.setVisibility(View.VISIBLE); romNameTextView.setVisibility(View.VISIBLE);
romNameTextView.setText(new File(path).getName()); romNameTextView.setText(new File(path).getName());
Settings.setLastRomDir(getActivity(), new File(path).getParent()); Settings.setLastRomDir(getActivity(), new File(path).getParent());
SnesSmcHeader checker = new SnesSmcHeader(); SnesSmcHeader checker = new SnesSmcHeader();
if (checker.isHasSmcHeader(new File(path))) { if (checker.isHasSmcHeader(new File(path))) {
action = Globals.ACTION_SNES_DELETE_SMC_HEADER; action = Action.SNES_DELETE_SMC_HEADER;
headerCardView.setVisibility(View.GONE); headerCardView.setVisibility(View.GONE);
headerInfoTextView.setText(R.string.snes_smc_header_will_be_removed); headerInfoTextView.setText(R.string.snes_smc_header_will_be_removed);
} else { } else {
action = Globals.ACTION_SNES_ADD_SMC_HEADER; action = Action.SNES_ADD_SMC_HEADER;
headerCardView.setVisibility(View.VISIBLE); headerCardView.setVisibility(View.VISIBLE);
headerInfoTextView.setText(R.string.snes_smc_header_will_be_added); headerInfoTextView.setText(R.string.snes_smc_header_will_be_added);
} }
headerPath = null; headerPath = null;
headerNameTextView.setText(R.string.main_activity_tap_to_select); headerNameTextView.setText(R.string.main_activity_tap_to_select);
break; break;
case SELECT_HEADER_FILE: case Action.SELECT_HEADER_FILE:
headerPath = path; headerPath = path;
headerNameTextView.setText(new File(path).getName()); headerNameTextView.setText(new File(path).getName());
break; break;
@ -192,7 +190,7 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic
intent.putExtra("headerPath", headerPath); intent.putExtra("headerPath", headerPath);
getActivity().startService(intent); getActivity().startService(intent);
if (action == Globals.ACTION_SNES_ADD_SMC_HEADER) { if (action == Action.SNES_ADD_SMC_HEADER) {
Toast.makeText(getActivity(), R.string.notify_snes_add_smc_header_stared_check_noify, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), R.string.notify_snes_add_smc_header_stared_check_noify, Toast.LENGTH_SHORT).show();
} else { } else {
Toast.makeText(getActivity(), R.string.notify_snes_delete_smc_header_stared_check_noify, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), R.string.notify_snes_delete_smc_header_stared_check_noify, Toast.LENGTH_SHORT).show();