这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@rubinstory
Copy link

Refactored Overall project files from Pusan National University.

rubinstory and others added 30 commits May 12, 2022 15:06
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()
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
…`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
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.
taehoonkange and others added 6 commits May 26, 2022 19:01
…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()`
@rubinstory rubinstory closed this May 26, 2022
@Override
public void onTermuxSessionExited(final TermuxSession termuxSession) {
if (termuxSession != null) {
boolean isTermuxSession = termuxSession != null;
Copy link
Member

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.

@agnostic-apollo
Copy link
Member

Do not modify the SettingsActivity, RootPreferencesFragment and the other PreferenceDataStore, or move them to individual class file. I kept the fragments and datastores in same classes since they served similar functionalities and splitting would just create too many files without any need.

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);
Copy link
Member

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)) {
Copy link
Member

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) {
Copy link
Member

@agnostic-apollo agnostic-apollo May 29, 2022

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) {
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

@agnostic-apollo agnostic-apollo May 29, 2022

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{
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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);
}


Copy link
Member

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) {
Copy link
Member

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;
Copy link
Member

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) {

Copy link
Member

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";
}


Copy link
Member

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));

Copy link
Member

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));
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

@agnostic-apollo agnostic-apollo May 29, 2022

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;

Copy link
Member

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);
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants