-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Refactoring Overall files #2786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
test: git test with change readme
MethodInvokeResult Since FieldInvokeResult and MethodInvokeResult class has a lot in common, extracting them as superclass seems to be more useful for adding other "InvokeResult" classes in the future.
Added|Fixed: Extract Superclass from FieldInvokeResult and
Considering a boolean return type and CamelCase style, changed the function name to isInTable.
According to the code point, the cases where the width is 0 are defined. For clarity, Renamed function variable `ucs` to `codePoint`.
Extract getSoftwareInfoMarkDownString(), getHardwareInfoMarkdownString() from getDeviceInfoMarkdownString() due to the complex structure of the method. getSoft...String() returns information of device software in markdown language. getHard...String() returns information of device hardware in markdown language.
refactor: Extract methods from getDeviceInfoMarkdownString()
Refactor/wc width
Add isString, isEmpty, isREL boolean variables to the method. Now we can check the if statement's condition more easily.
refactor: Add Explaining Variables at appendPropertyToMarkdownIfSet()
Changed: Refator `WCWidth.java`
Considering a boolean return type and CamelCase style, changed the function name to isInTable.
According to the code point, the cases where the width is 0 are defined. For clarity, Renamed function variable `ucs` to `codePoint`.
result != PERMISSION_GRANTED -> boolean permissionGranted context instanceof App..Activity -> boolean isApp..Activity context instanceof Activity -> booelean isActivity
Replaced Error Codes 0 with IllegalArgumentException by each case.
Extract hasBootstrapError() from setupBootstrapIfNeeded() due to the duplicate code of the method
Refactor/terminal view
…`parse()` Include only the parts that make sense for the try-catch.
The code has two methods and variable name isn't good. so it needs to refactor codes. `getAction`, `chooseAction` are extracted. The code is figured out easily to rename variables
…) for more readable
In `tryParseColor()` from `TerminalColors.java` and `updateWith()` from `TerminalColorScheme.java`, setting parsed color is wrapped by try-catch. In `TerminalTest.java`, wrong input testing code is wrapped by try-catch.
Refactor/terminal colors
…ent.java` `configureTermuxAPIPreference()`, `configureTermuxFloatPreference()`, etc are very similar method. so Using Template method reduces overlapped codes. At first, make abstract class
Changed: Apply State pattern in `TerminalEmulator`
Apply Template method for `configureTermuxPreference` and delete orginal code about `configureTermuxAPIPreference()`
…ent.java Added: Add `configureTermuxPreference.java` for `RootPreferencesFragment.java`
Changed: Apply State pattern in `TerminalEmulator`
…eference.java Added: extract class `configureTermuxAPIPreference()`
| @Override | ||
| public void onTermuxSessionExited(final TermuxSession termuxSession) { | ||
| if (termuxSession != null) { | ||
| boolean isTermuxSession = termuxSession != null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These and all the other if conditions extracted to boolean are useless and server no purpose, using an if condition already implies that one or more conditions will be supplied in it. Do not do this. If there are multiple conditions that are too complex, they can be split on multiple lines, in some case extraction to boolean is indeed fine.
|
Do not modify the |
| Log.d(getFullTag(tag), message); | ||
| else if (logPriority == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE) | ||
| Log.v(getFullTag(tag), message); | ||
| boolean higherThanNormal = (CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this. Need to minimize if conditions calculated for log statements.
| */ | ||
| public static boolean getBoolean(SharedPreferences sharedPreferences, String key, boolean def) { | ||
| if (sharedPreferences == null) { | ||
| if (isSharedPreferenceNull(sharedPreferences)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this.
| /** Termux and plugin apps directory */ | ||
| public static final File TERMUX_APPS_DIR = new File(TERMUX_APPS_DIR_PATH); | ||
|
|
||
| public static StringBuilder buildScript(String filesDir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this. Not the place for scripts.
| public boolean onUp(MotionEvent event) { | ||
| mScrollRemainder = 0.0f; | ||
| if (mEmulator != null && mEmulator.isMouseTrackingActive() && !event.isFromSource(InputDevice.SOURCE_MOUSE) && !isSelectingText() && !scrolledWithFinger) { | ||
| if (!isEmulatorNull() && mEmulator.isMouseTrackingActive() && !event.isFromSource(InputDevice.SOURCE_MOUSE) && !isSelectingText() && !scrolledWithFinger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this.
| public static void appendPropertyToMarkdownIfSet(StringBuilder markdownString, String label, Object value) { | ||
| if (value == null) return; | ||
| if (value instanceof String && (((String) value).isEmpty()) || "REL".equals(value)) return; | ||
| boolean isString = value instanceof String; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this.
| for (String permission : permissions) { | ||
| result = ContextCompat.checkSelfPermission(context, permission); | ||
| if (result != PackageManager.PERMISSION_GRANTED) { | ||
| boolean permissionGranted = (result == PackageManager.PERMISSION_GRANTED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this and below ones.
| HashSet<FilePermission> perms = new HashSet<>(); | ||
|
|
||
| if ((bits & UnixConstants.S_IRUSR) > 0) | ||
| boolean canOwnerRead = ((bits & UnixConstants.S_IRUSR) > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this. Can add comments if you must, although code is pretty clear and is from AOSP.
| public boolean success; | ||
| public Object value; | ||
|
|
||
| public static class MethodInvokeResult extends InvokeResult{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be a space before {.
| public class ShellUtils { | ||
|
|
||
| public static int getPid(Process p) { | ||
| int invalid = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this.
|
|
||
| // If an uncaught exception, then do not notify since the termux app itself would be crashing | ||
| if (TYPE.UNCAUGHT_EXCEPTION.equals(mType) && TermuxConstants.TERMUX_PACKAGE_NAME.equals(currentPackageName)) | ||
| boolean isUncaughtException = TYPE.UNCAUGHT_EXCEPTION.equals(mType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this.
| sendCrashReportNotification(context, logTag, null, null, reportString, false, false, null, false); | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't remove these functions. These are library utility functions for callers.
|
|
||
| private static final String LOG_TAG = "TermuxFileUtils"; | ||
|
|
||
| private static boolean isStringHasValue(String str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file.
|
|
||
| public final class TextInputDialogUtils { | ||
|
|
||
| public static final int PADDING_PER_DIP_AT_TOPANDSIDES = 16; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file.
|
|
||
| int nextNotificationId = lastNotificationId + 1; | ||
| while(nextNotificationId == TermuxConstants.TERMUX_APP_NOTIFICATION_ID || nextNotificationId == TermuxConstants.TERMUX_RUN_COMMAND_NOTIFICATION_ID) { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file.
| resultConfig.resultFileBasename = ShellUtils.getExecutableBasename(executionCommand.executable) + "-" + AndroidUtils.getCurrentMilliSecondLocalTimeStamp() + ".log"; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file.
| TermuxPluginUtils.sendPluginCommandErrorNotification(context, LOG_TAG, | ||
| localSocketRunConfig.getTitle() + " Socket Server Error", error.getMinimalErrorString(), | ||
| LocalSocketManager.getErrorMarkdownString(error, localSocketRunConfig, clientSocket)); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file.
| * mode is set to {@link NightMode#SYSTEM} and night mode is enabled by system. */ | ||
| public static boolean shouldEnableDarkTheme(Context context, String name) { | ||
| if (NightMode.TRUE.getName().equals(name)) | ||
| boolean isNightMode = (NightMode.TRUE.getName().equals(name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file.
| /** Get {@link #ATTR_TEXT_COLOR_PRIMARY} value being used by current theme. */ | ||
| public static int getTextColorPrimary(Context context) { | ||
| return getSystemAttrColor(context, ATTR_TEXT_COLOR_PRIMARY); | ||
| return getSystemAttrColor(context, ATTR_TEXT_COLOR_PRIMARY, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intermediate library utility functions are often used that pass specific/default values.
| ", displayOrientation=" + displayOrientation); | ||
| } | ||
|
|
||
| boolean isStatusBarHeightTop = (statusBarHeight == windowRect.top); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file. Only 2 statements will ever exist, so case not worthwhile.
| return r1.left < r1.right && r1.top < r1.bottom | ||
| // now check if above | ||
| && r1.left <= r2.left && r1.bottom >= r2.bottom; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this too.
|
|
||
| JSONObject jobject = normalizeKeyConfig(key); | ||
|
|
||
| JSONObject jsonObject = normalizeKeyConfig(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip this file too. Rename might be fine, not the if to boolean.
Refactored Overall project files from Pusan National University.