2015-11-29 00:08:18 +00:00
|
|
|
package com.termux.app;
|
|
|
|
|
2021-04-07 06:31:30 +00:00
|
|
|
import com.termux.shared.data.DataUtils;
|
Refactor TermuxActivity
This commit majorly refactors `TermuxActivity` and moves its view components and functions into dedicated classes.
- The view layouts and ids have been given meaningful names, like `termux_activity.xml`.
- The `TerminalToolbarViewPager` class has been created to handle the now called toolbar that shows on the bottom of the terminal view. It currently contains extra keys view defined by `terminal_toolbar_extra_keys_view.xml` file and a text input view defined by `terminal_toolbar_text_input_view.xml` file when user can switch to by swiping left. The input text will now be preserved if android destroys the activity or its recreated.
- The `TermuxSessionsListViewController` class has been created to handle view related functionality of the termux sessions list shown in the left drawer, namely view creation, `onItemClick()`, `onItemLongClick()`, etc. Its list view is defined by `termux_activity.xml` file and each item's layout is defined by the `terminal_sessions_list_item.xml` file.
- The `TextDataUtils` class has been added to the `com.termux.app.utils` package for text utils.
- The design for the `SessionChangedCallback` interface for `TerminalSession` has been majorly changed. Firstly, it has been renamed and moved from `TerminalSession` to the dedicated `TerminalSessionClient` class file. The interface now also supports the termux app centralized logging framework so that `TerminalSession` and `TerminalEmulator` can use them. Previously, `TermuxService` was implementing a wrapper interface, which would then call the real interface defined by the `TermuxActivity` if it was currently bound to the service. This cluttered and partially duplicated the code. Now, the implementation is defined by the `TermuxSessionClientBase` and `TermuxSessionClient` classes. The `TermuxSessionClientBase` implements the `TerminalSessionClient` interface but the definition of the activity related functions do not do anything, only the background ones like the logging functions are fully implemented. The `TermuxSessionClient` class inherits from the `TermuxSessionClientBase` class and provides the implementation for the activity related functions. The design for how this works is that if the `TermuxService` is not bound to `TermuxActivity`, it just passes the `TermuxSessionClientBase` implementation to `TerminalSession`. If the activity is bound at some point, then in `onServiceConnected()` it replaces/updates the client objects stored in `TerminalSession` and `TerminalEmulator` with `TermuxSessionClient`, and then replaces them back with `TermuxSessionClientBase` in `onDestroy()`. This seems to be working for now without an issue.
2021-03-16 00:01:09 +00:00
|
|
|
|
2020-01-05 00:02:13 +00:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
2015-11-29 00:08:18 +00:00
|
|
|
|
2015-11-29 00:55:41 +00:00
|
|
|
import java.util.Collections;
|
2015-11-29 00:08:18 +00:00
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
2020-01-05 00:02:13 +00:00
|
|
|
public class TermuxActivityTest {
|
2015-11-29 00:08:18 +00:00
|
|
|
|
2020-01-05 00:02:13 +00:00
|
|
|
private void assertUrlsAre(String text, String... urls) {
|
|
|
|
LinkedHashSet<String> expected = new LinkedHashSet<>();
|
|
|
|
Collections.addAll(expected, urls);
|
2021-03-28 04:08:45 +00:00
|
|
|
Assert.assertEquals(expected, DataUtils.extractUrls(text));
|
2020-01-05 00:02:13 +00:00
|
|
|
}
|
2015-11-29 00:08:18 +00:00
|
|
|
|
2020-01-05 00:02:13 +00:00
|
|
|
@Test
|
|
|
|
public void testExtractUrls() {
|
|
|
|
assertUrlsAre("hello http://example.com world", "http://example.com");
|
2015-11-29 00:08:18 +00:00
|
|
|
|
2020-01-05 00:02:13 +00:00
|
|
|
assertUrlsAre("http://example.com\nhttp://another.com", "http://example.com", "http://another.com");
|
2015-11-29 00:08:18 +00:00
|
|
|
|
2020-01-05 00:02:13 +00:00
|
|
|
assertUrlsAre("hello http://example.com world and http://more.example.com with secure https://more.example.com",
|
|
|
|
"http://example.com", "http://more.example.com", "https://more.example.com");
|
2020-03-12 17:00:37 +00:00
|
|
|
|
|
|
|
assertUrlsAre("hello https://example.com/#bar https://example.com/foo#bar",
|
|
|
|
"https://example.com/#bar", "https://example.com/foo#bar");
|
2020-01-05 00:02:13 +00:00
|
|
|
}
|
2015-11-29 00:08:18 +00:00
|
|
|
|
|
|
|
}
|