Compare commits
2 Commits
3357fe76d4
...
5faa970b79
| Author | SHA1 | Date | |
|---|---|---|---|
| 5faa970b79 | |||
| 0c3b7054bd |
@@ -32,6 +32,7 @@ dependencies {
|
|||||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||||
implementation 'com.google.android.material:material:1.4.0'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||||
|
implementation 'androidx.security:security-crypto:1.1.0-alpha06'
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
|
|||||||
@@ -31,6 +31,15 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".UserManagementActivity"
|
||||||
|
android:label="Manage Users"
|
||||||
|
android:parentActivityName=".MainActivity">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value=".MainActivity" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".FTPService"
|
android:name=".FTPService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class FTPServer {
|
|||||||
private Uri rootDirectoryUri;
|
private Uri rootDirectoryUri;
|
||||||
private int minDataPort = 0;
|
private int minDataPort = 0;
|
||||||
private int maxDataPort = 0;
|
private int maxDataPort = 0;
|
||||||
|
private FTPUserManager userManager;
|
||||||
|
|
||||||
public FTPServer(Context context) {
|
public FTPServer(Context context) {
|
||||||
this(context, DEFAULT_PORT, null, 0, 0);
|
this(context, DEFAULT_PORT, null, 0, 0);
|
||||||
@@ -45,6 +46,7 @@ public class FTPServer {
|
|||||||
this.minDataPort = minDataPort;
|
this.minDataPort = minDataPort;
|
||||||
this.maxDataPort = maxDataPort;
|
this.maxDataPort = maxDataPort;
|
||||||
this.executorService = Executors.newFixedThreadPool(MAX_CONNECTIONS);
|
this.executorService = Executors.newFixedThreadPool(MAX_CONNECTIONS);
|
||||||
|
this.userManager = FTPUserManager.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
@@ -64,7 +66,7 @@ public class FTPServer {
|
|||||||
Socket clientSocket = serverSocket.accept();
|
Socket clientSocket = serverSocket.accept();
|
||||||
Log.i(TAG, "New client connection from: " + clientSocket.getInetAddress());
|
Log.i(TAG, "New client connection from: " + clientSocket.getInetAddress());
|
||||||
|
|
||||||
FTPSession session = new FTPSession(clientSocket, context, rootDirectoryUri, minDataPort, maxDataPort);
|
FTPSession session = new FTPSession(clientSocket, context, rootDirectoryUri, minDataPort, maxDataPort, userManager);
|
||||||
executorService.execute(session);
|
executorService.execute(session);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -33,21 +33,27 @@ public class FTPSession implements Runnable {
|
|||||||
private boolean useUtf8 = true; // UTF-8 enabled by default for better compatibility
|
private boolean useUtf8 = true; // UTF-8 enabled by default for better compatibility
|
||||||
private int minDataPort = 0;
|
private int minDataPort = 0;
|
||||||
private int maxDataPort = 0;
|
private int maxDataPort = 0;
|
||||||
|
private FTPUserManager userManager;
|
||||||
|
|
||||||
public FTPSession(Socket socket, Context context) {
|
public FTPSession(Socket socket, Context context) {
|
||||||
this(socket, context, null, 0, 0);
|
this(socket, context, null, 0, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri) {
|
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri) {
|
||||||
this(socket, context, rootDirectoryUri, 0, 0);
|
this(socket, context, rootDirectoryUri, 0, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri, int minDataPort, int maxDataPort) {
|
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri, int minDataPort, int maxDataPort) {
|
||||||
|
this(socket, context, rootDirectoryUri, minDataPort, maxDataPort, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri, int minDataPort, int maxDataPort, FTPUserManager userManager) {
|
||||||
this.controlSocket = socket;
|
this.controlSocket = socket;
|
||||||
this.fileSystem = new FTPFileSystem(context, rootDirectoryUri);
|
this.fileSystem = new FTPFileSystem(context, rootDirectoryUri);
|
||||||
this.dataConnection = null;
|
this.dataConnection = null;
|
||||||
this.minDataPort = minDataPort;
|
this.minDataPort = minDataPort;
|
||||||
this.maxDataPort = maxDataPort;
|
this.maxDataPort = maxDataPort;
|
||||||
|
this.userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -161,10 +167,16 @@ public class FTPSession implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple authentication - accept any password for now
|
// Authenticate using FTPUserManager
|
||||||
// In production, implement proper authentication
|
if (userManager != null && userManager.authenticate(username, password)) {
|
||||||
isAuthenticated = true;
|
isAuthenticated = true;
|
||||||
sendResponse(FTPResponse.USER_LOGGED_IN, "User logged in");
|
sendResponse(FTPResponse.USER_LOGGED_IN, "User logged in");
|
||||||
|
Log.i(TAG, "User authenticated: " + username);
|
||||||
|
} else {
|
||||||
|
isAuthenticated = false;
|
||||||
|
sendResponse(FTPResponse.NOT_LOGGED_IN, "Authentication failed");
|
||||||
|
Log.w(TAG, "Authentication failed for user: " + username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleQuit() throws IOException {
|
private void handleQuit() throws IOException {
|
||||||
@@ -182,8 +194,6 @@ public class FTPSession implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String path = fileSystem.getCurrentPath();
|
String path = fileSystem.getCurrentPath();
|
||||||
// Convert path to NFD format for MacOS compatibility
|
|
||||||
path = denormalizeFilename(path);
|
|
||||||
sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + path + "\" is current directory");
|
sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + path + "\" is current directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,8 +213,6 @@ public class FTPSession implements Runnable {
|
|||||||
|
|
||||||
if (fileSystem.changeDirectory(path)) {
|
if (fileSystem.changeDirectory(path)) {
|
||||||
String currentPath = fileSystem.getCurrentPath();
|
String currentPath = fileSystem.getCurrentPath();
|
||||||
// Convert path to NFD format for MacOS compatibility
|
|
||||||
currentPath = denormalizeFilename(currentPath);
|
|
||||||
sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath);
|
sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath);
|
||||||
} else {
|
} else {
|
||||||
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to change directory");
|
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to change directory");
|
||||||
@@ -219,8 +227,6 @@ public class FTPSession implements Runnable {
|
|||||||
|
|
||||||
if (fileSystem.changeToParentDirectory()) {
|
if (fileSystem.changeToParentDirectory()) {
|
||||||
String currentPath = fileSystem.getCurrentPath();
|
String currentPath = fileSystem.getCurrentPath();
|
||||||
// Convert path to NFD format for MacOS compatibility
|
|
||||||
currentPath = denormalizeFilename(currentPath);
|
|
||||||
sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath);
|
sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath);
|
||||||
} else {
|
} else {
|
||||||
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Already at root directory");
|
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Already at root directory");
|
||||||
@@ -239,8 +245,6 @@ public class FTPSession implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String fileList = fileSystem.formatFileList(true);
|
String fileList = fileSystem.formatFileList(true);
|
||||||
// Convert filenames to NFD format for MacOS compatibility
|
|
||||||
fileList = convertFileListToNFD(fileList);
|
|
||||||
|
|
||||||
sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for directory list");
|
sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for directory list");
|
||||||
|
|
||||||
@@ -272,8 +276,6 @@ public class FTPSession implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String fileList = fileSystem.formatFileList(false);
|
String fileList = fileSystem.formatFileList(false);
|
||||||
// Convert filenames to NFD format for MacOS compatibility
|
|
||||||
fileList = convertFileListToNFD(fileList);
|
|
||||||
|
|
||||||
sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for name list");
|
sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for name list");
|
||||||
|
|
||||||
@@ -309,8 +311,6 @@ public class FTPSession implements Runnable {
|
|||||||
|
|
||||||
if (fileSystem.makeDirectory(dirName)) {
|
if (fileSystem.makeDirectory(dirName)) {
|
||||||
String newPath = fileSystem.getCurrentPath() + "/" + dirName;
|
String newPath = fileSystem.getCurrentPath() + "/" + dirName;
|
||||||
// Convert path to NFD format for MacOS compatibility (NFC -> NFD for display)
|
|
||||||
newPath = denormalizeFilename(newPath);
|
|
||||||
sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + newPath + "\" directory created");
|
sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + newPath + "\" directory created");
|
||||||
} else {
|
} else {
|
||||||
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to create directory");
|
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to create directory");
|
||||||
|
|||||||
53
app/src/main/java/be/gyu/android/server/ftp/FTPUser.java
Normal file
53
app/src/main/java/be/gyu/android/server/ftp/FTPUser.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package be.gyu.android.server.ftp;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public class FTPUser {
|
||||||
|
private String username;
|
||||||
|
private String passwordHash;
|
||||||
|
private long createdTimestamp;
|
||||||
|
|
||||||
|
public FTPUser(String username, String passwordHash) {
|
||||||
|
this.username = username;
|
||||||
|
this.passwordHash = passwordHash;
|
||||||
|
this.createdTimestamp = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FTPUser(String username, String passwordHash, long createdTimestamp) {
|
||||||
|
this.username = username;
|
||||||
|
this.passwordHash = passwordHash;
|
||||||
|
this.createdTimestamp = createdTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPasswordHash() {
|
||||||
|
return passwordHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCreatedTimestamp() {
|
||||||
|
return createdTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPasswordHash(String passwordHash) {
|
||||||
|
this.passwordHash = passwordHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject toJson() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("username", username);
|
||||||
|
json.put("passwordHash", passwordHash);
|
||||||
|
json.put("createdTimestamp", createdTimestamp);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FTPUser fromJson(JSONObject json) throws JSONException {
|
||||||
|
String username = json.getString("username");
|
||||||
|
String passwordHash = json.getString("passwordHash");
|
||||||
|
long createdTimestamp = json.optLong("createdTimestamp", System.currentTimeMillis());
|
||||||
|
return new FTPUser(username, passwordHash, createdTimestamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
211
app/src/main/java/be/gyu/android/server/ftp/FTPUserManager.java
Normal file
211
app/src/main/java/be/gyu/android/server/ftp/FTPUserManager.java
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
package be.gyu.android.server.ftp;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.security.crypto.EncryptedSharedPreferences;
|
||||||
|
import androidx.security.crypto.MasterKey;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FTPUserManager {
|
||||||
|
private static final String TAG = "FTPUserManager";
|
||||||
|
private static final String PREF_NAME = "ftp_users_encrypted";
|
||||||
|
private static final String KEY_USERS = "ftp_users";
|
||||||
|
|
||||||
|
private static FTPUserManager instance;
|
||||||
|
private SharedPreferences encryptedPrefs;
|
||||||
|
|
||||||
|
private FTPUserManager(Context context) {
|
||||||
|
try {
|
||||||
|
MasterKey masterKey = new MasterKey.Builder(context)
|
||||||
|
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
encryptedPrefs = EncryptedSharedPreferences.create(
|
||||||
|
context,
|
||||||
|
PREF_NAME,
|
||||||
|
masterKey,
|
||||||
|
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
||||||
|
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Failed to create encrypted preferences: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized FTPUserManager getInstance(Context context) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new FTPUserManager(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean addUser(String username, String password) {
|
||||||
|
if (!isValidUsername(username) || !isValidPassword(password)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userExists(username)) {
|
||||||
|
Log.w(TAG, "User already exists: " + username);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FTPUser> users = loadUsers();
|
||||||
|
String passwordHash = hashPassword(password, username);
|
||||||
|
users.add(new FTPUser(username, passwordHash));
|
||||||
|
saveUsers(users);
|
||||||
|
|
||||||
|
Log.i(TAG, "User added: " + username);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean updateUser(String username, String newPassword) {
|
||||||
|
if (!isValidPassword(newPassword)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FTPUser> users = loadUsers();
|
||||||
|
for (FTPUser user : users) {
|
||||||
|
if (user.getUsername().equals(username)) {
|
||||||
|
String newPasswordHash = hashPassword(newPassword, username);
|
||||||
|
user.setPasswordHash(newPasswordHash);
|
||||||
|
saveUsers(users);
|
||||||
|
Log.i(TAG, "User updated: " + username);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.w(TAG, "User not found for update: " + username);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean deleteUser(String username) {
|
||||||
|
List<FTPUser> users = loadUsers();
|
||||||
|
|
||||||
|
// Prevent deleting the last user
|
||||||
|
if (users.size() <= 1) {
|
||||||
|
Log.w(TAG, "Cannot delete last user");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean removed = users.removeIf(user -> user.getUsername().equals(username));
|
||||||
|
if (removed) {
|
||||||
|
saveUsers(users);
|
||||||
|
Log.i(TAG, "User deleted: " + username);
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized List<FTPUser> getAllUsers() {
|
||||||
|
return new ArrayList<>(loadUsers());
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized FTPUser getUser(String username) {
|
||||||
|
List<FTPUser> users = loadUsers();
|
||||||
|
for (FTPUser user : users) {
|
||||||
|
if (user.getUsername().equals(username)) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean authenticate(String username, String password) {
|
||||||
|
FTPUser user = getUser(username);
|
||||||
|
if (user == null) {
|
||||||
|
Log.w(TAG, "Authentication failed - user not found: " + username);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String passwordHash = hashPassword(password, username);
|
||||||
|
boolean authenticated = passwordHash.equals(user.getPasswordHash());
|
||||||
|
|
||||||
|
if (authenticated) {
|
||||||
|
Log.i(TAG, "User authenticated: " + username);
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Authentication failed - wrong password: " + username);
|
||||||
|
}
|
||||||
|
|
||||||
|
return authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean userExists(String username) {
|
||||||
|
return getUser(username) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidUsername(String username) {
|
||||||
|
if (username == null || username.trim().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
username = username.trim();
|
||||||
|
return username.length() >= 3 &&
|
||||||
|
username.length() <= 20 &&
|
||||||
|
username.matches("^[a-zA-Z0-9_]+$");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidPassword(String password) {
|
||||||
|
return password != null && password.length() >= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String hashPassword(String password, String salt) {
|
||||||
|
try {
|
||||||
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||||
|
String saltedPassword = salt + password;
|
||||||
|
byte[] hash = digest.digest(saltedPassword.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
// Convert to hex string
|
||||||
|
StringBuilder hexString = new StringBuilder();
|
||||||
|
for (byte b : hash) {
|
||||||
|
String hex = Integer.toHexString(0xff & b);
|
||||||
|
if (hex.length() == 1) hexString.append('0');
|
||||||
|
hexString.append(hex);
|
||||||
|
}
|
||||||
|
return hexString.toString();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
Log.e(TAG, "SHA-256 not available: " + e.getMessage());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FTPUser> loadUsers() {
|
||||||
|
List<FTPUser> users = new ArrayList<>();
|
||||||
|
String usersJson = encryptedPrefs.getString(KEY_USERS, "[]");
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(usersJson);
|
||||||
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
JSONObject userJson = jsonArray.getJSONObject(i);
|
||||||
|
users.add(FTPUser.fromJson(userJson));
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(TAG, "Error loading users: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveUsers(List<FTPUser> users) {
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
for (FTPUser user : users) {
|
||||||
|
jsonArray.put(user.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedPrefs.edit()
|
||||||
|
.putString(KEY_USERS, jsonArray.toString())
|
||||||
|
.apply();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(TAG, "Error saving users: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private Button saveSettingsButton;
|
private Button saveSettingsButton;
|
||||||
private EditText minDataPortEditText;
|
private EditText minDataPortEditText;
|
||||||
private EditText maxDataPortEditText;
|
private EditText maxDataPortEditText;
|
||||||
|
private Button manageUsersButton;
|
||||||
|
|
||||||
private FTPConfig config;
|
private FTPConfig config;
|
||||||
private ActivityResultLauncher<Uri> directoryPickerLauncher;
|
private ActivityResultLauncher<Uri> directoryPickerLauncher;
|
||||||
@@ -54,6 +55,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
loadSettings();
|
loadSettings();
|
||||||
setupListeners();
|
setupListeners();
|
||||||
requestPermissions();
|
requestPermissions();
|
||||||
|
initializeDefaultUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDirectoryPicker() {
|
private void setupDirectoryPicker() {
|
||||||
@@ -95,6 +97,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
saveSettingsButton = findViewById(R.id.saveSettingsButton);
|
saveSettingsButton = findViewById(R.id.saveSettingsButton);
|
||||||
minDataPortEditText = findViewById(R.id.minDataPortEditText);
|
minDataPortEditText = findViewById(R.id.minDataPortEditText);
|
||||||
maxDataPortEditText = findViewById(R.id.maxDataPortEditText);
|
maxDataPortEditText = findViewById(R.id.maxDataPortEditText);
|
||||||
|
manageUsersButton = findViewById(R.id.manageUsersButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSettings() {
|
private void loadSettings() {
|
||||||
@@ -121,6 +124,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
stopButton.setOnClickListener(v -> stopFTPServer());
|
stopButton.setOnClickListener(v -> stopFTPServer());
|
||||||
selectDirButton.setOnClickListener(v -> selectDirectory());
|
selectDirButton.setOnClickListener(v -> selectDirectory());
|
||||||
saveSettingsButton.setOnClickListener(v -> saveSettings());
|
saveSettingsButton.setOnClickListener(v -> saveSettings());
|
||||||
|
manageUsersButton.setOnClickListener(v -> openUserManagement());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectDirectory() {
|
private void selectDirectory() {
|
||||||
@@ -313,4 +317,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
isServerRunning = isServiceRunning();
|
isServerRunning = isServiceRunning();
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openUserManagement() {
|
||||||
|
Intent intent = new Intent(this, UserManagementActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeDefaultUser() {
|
||||||
|
FTPUserManager userManager = FTPUserManager.getInstance(this);
|
||||||
|
if (userManager.getAllUsers().isEmpty()) {
|
||||||
|
userManager.addUser("admin", "admin");
|
||||||
|
Toast.makeText(this, "Default user created: admin/admin\nPlease change the password in User Management", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
package be.gyu.android.server.ftp;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserManagementActivity extends AppCompatActivity {
|
||||||
|
private FTPUserManager userManager;
|
||||||
|
private ListView userListView;
|
||||||
|
private UserListAdapter userAdapter;
|
||||||
|
private List<FTPUser> userList;
|
||||||
|
private TextView emptyView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_user_management);
|
||||||
|
|
||||||
|
userManager = FTPUserManager.getInstance(this);
|
||||||
|
|
||||||
|
initViews();
|
||||||
|
setupListeners();
|
||||||
|
refreshUserList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initViews() {
|
||||||
|
userListView = findViewById(R.id.userListView);
|
||||||
|
emptyView = findViewById(R.id.emptyView);
|
||||||
|
Button addUserButton = findViewById(R.id.addUserButton);
|
||||||
|
|
||||||
|
userList = new ArrayList<>();
|
||||||
|
userAdapter = new UserListAdapter();
|
||||||
|
userListView.setAdapter(userAdapter);
|
||||||
|
userListView.setEmptyView(emptyView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupListeners() {
|
||||||
|
findViewById(R.id.addUserButton).setOnClickListener(v -> showAddUserDialog());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAddUserDialog() {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_add_user, null);
|
||||||
|
builder.setView(dialogView);
|
||||||
|
|
||||||
|
TextView dialogTitle = dialogView.findViewById(R.id.dialogTitle);
|
||||||
|
EditText usernameEditText = dialogView.findViewById(R.id.usernameEditText);
|
||||||
|
EditText passwordEditText = dialogView.findViewById(R.id.passwordEditText);
|
||||||
|
EditText confirmPasswordEditText = dialogView.findViewById(R.id.confirmPasswordEditText);
|
||||||
|
TextView errorTextView = dialogView.findViewById(R.id.errorTextView);
|
||||||
|
Button saveButton = dialogView.findViewById(R.id.saveButton);
|
||||||
|
Button cancelButton = dialogView.findViewById(R.id.cancelButton);
|
||||||
|
|
||||||
|
dialogTitle.setText("Add User");
|
||||||
|
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
|
||||||
|
saveButton.setOnClickListener(v -> {
|
||||||
|
String username = usernameEditText.getText().toString().trim();
|
||||||
|
String password = passwordEditText.getText().toString();
|
||||||
|
String confirmPassword = confirmPasswordEditText.getText().toString();
|
||||||
|
|
||||||
|
// Validate username
|
||||||
|
if (username.isEmpty()) {
|
||||||
|
errorTextView.setText("Username is required");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userManager.isValidUsername(username)) {
|
||||||
|
errorTextView.setText("Username must be 3-20 characters, alphanumeric + underscore");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userManager.userExists(username)) {
|
||||||
|
errorTextView.setText("Username already exists");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate password
|
||||||
|
if (password.isEmpty()) {
|
||||||
|
errorTextView.setText("Password is required");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userManager.isValidPassword(password)) {
|
||||||
|
errorTextView.setText("Password must be at least 4 characters");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.equals(confirmPassword)) {
|
||||||
|
errorTextView.setText("Passwords do not match");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add user
|
||||||
|
if (userManager.addUser(username, password)) {
|
||||||
|
Toast.makeText(this, "User added successfully", Toast.LENGTH_SHORT).show();
|
||||||
|
refreshUserList();
|
||||||
|
dialog.dismiss();
|
||||||
|
} else {
|
||||||
|
errorTextView.setText("Failed to add user");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelButton.setOnClickListener(v -> dialog.dismiss());
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showEditUserDialog(FTPUser user) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_add_user, null);
|
||||||
|
builder.setView(dialogView);
|
||||||
|
|
||||||
|
TextView dialogTitle = dialogView.findViewById(R.id.dialogTitle);
|
||||||
|
EditText usernameEditText = dialogView.findViewById(R.id.usernameEditText);
|
||||||
|
EditText passwordEditText = dialogView.findViewById(R.id.passwordEditText);
|
||||||
|
EditText confirmPasswordEditText = dialogView.findViewById(R.id.confirmPasswordEditText);
|
||||||
|
TextView errorTextView = dialogView.findViewById(R.id.errorTextView);
|
||||||
|
Button saveButton = dialogView.findViewById(R.id.saveButton);
|
||||||
|
Button cancelButton = dialogView.findViewById(R.id.cancelButton);
|
||||||
|
|
||||||
|
dialogTitle.setText("Edit User");
|
||||||
|
usernameEditText.setText(user.getUsername());
|
||||||
|
usernameEditText.setEnabled(false);
|
||||||
|
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
|
||||||
|
saveButton.setOnClickListener(v -> {
|
||||||
|
String password = passwordEditText.getText().toString();
|
||||||
|
String confirmPassword = confirmPasswordEditText.getText().toString();
|
||||||
|
|
||||||
|
// Validate password
|
||||||
|
if (password.isEmpty()) {
|
||||||
|
errorTextView.setText("Password is required");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userManager.isValidPassword(password)) {
|
||||||
|
errorTextView.setText("Password must be at least 4 characters");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.equals(confirmPassword)) {
|
||||||
|
errorTextView.setText("Passwords do not match");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update user
|
||||||
|
if (userManager.updateUser(user.getUsername(), password)) {
|
||||||
|
Toast.makeText(this, "User updated successfully", Toast.LENGTH_SHORT).show();
|
||||||
|
refreshUserList();
|
||||||
|
dialog.dismiss();
|
||||||
|
} else {
|
||||||
|
errorTextView.setText("Failed to update user");
|
||||||
|
errorTextView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelButton.setOnClickListener(v -> dialog.dismiss());
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showDeleteConfirmation(FTPUser user) {
|
||||||
|
// Check if this is the last user
|
||||||
|
if (userList.size() <= 1) {
|
||||||
|
Toast.makeText(this, "Cannot delete the last user", Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle("Delete User")
|
||||||
|
.setMessage("Are you sure you want to delete user '" + user.getUsername() + "'?")
|
||||||
|
.setPositiveButton("Delete", (dialog, which) -> {
|
||||||
|
if (userManager.deleteUser(user.getUsername())) {
|
||||||
|
Toast.makeText(this, "User deleted successfully", Toast.LENGTH_SHORT).show();
|
||||||
|
refreshUserList();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Failed to delete user", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("Cancel", null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshUserList() {
|
||||||
|
userList.clear();
|
||||||
|
userList.addAll(userManager.getAllUsers());
|
||||||
|
userAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class UserListAdapter extends BaseAdapter {
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return userList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(int position) {
|
||||||
|
return userList.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(UserManagementActivity.this)
|
||||||
|
.inflate(R.layout.item_user, parent, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
FTPUser user = userList.get(position);
|
||||||
|
|
||||||
|
TextView usernameView = convertView.findViewById(R.id.usernameTextView);
|
||||||
|
Button editButton = convertView.findViewById(R.id.editButton);
|
||||||
|
Button deleteButton = convertView.findViewById(R.id.deleteButton);
|
||||||
|
|
||||||
|
usernameView.setText(user.getUsername());
|
||||||
|
editButton.setOnClickListener(v -> showEditUserDialog(user));
|
||||||
|
deleteButton.setOnClickListener(v -> showDeleteConfirmation(user));
|
||||||
|
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -68,13 +68,24 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@id/startButton"
|
app:layout_constraintTop_toBottomOf="@id/startButton"
|
||||||
android:layout_marginTop="16dp" />
|
android:layout_marginTop="16dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/manageUsersButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Manage Users"
|
||||||
|
android:minWidth="150dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/stopButton"
|
||||||
|
android:layout_marginTop="16dp" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/divider"
|
android:id="@+id/divider"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:background="#CCCCCC"
|
android:background="#CCCCCC"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
app:layout_constraintTop_toBottomOf="@id/stopButton"
|
app:layout_constraintTop_toBottomOf="@id/manageUsersButton"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
|||||||
57
app/src/main/res/layout/activity_user_management.xml
Normal file
57
app/src/main/res/layout/activity_user_management.xml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="16dp"
|
||||||
|
tools:context=".UserManagementActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/titleTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="User Management"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
android:layout_marginTop="16dp" />
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/userListView"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/titleTextView"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/addUserButton"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/emptyView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="No users. Add your first user."
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="#999999"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/userListView"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/userListView"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/addUserButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Add User"
|
||||||
|
android:minWidth="150dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
94
app/src/main/res/layout/dialog_add_user.xml
Normal file
94
app/src/main/res/layout/dialog_add_user.xml
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="24dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dialogTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Add User"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Username:"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginBottom="4dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/usernameEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="3-20 characters, alphanumeric + underscore"
|
||||||
|
android:inputType="text"
|
||||||
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Password:"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginBottom="4dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/passwordEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Minimum 4 characters"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Confirm Password:"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginBottom="4dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/confirmPasswordEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Re-enter password"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:layout_marginBottom="8dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/errorTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Error message"
|
||||||
|
android:textColor="#FF0000"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="end">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/cancelButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Cancel"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_marginEnd="8dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/saveButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Save" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
34
app/src/main/res/layout/item_user.xml
Normal file
34
app/src/main/res/layout/item_user.xml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/usernameTextView"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="Username" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/editButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Edit"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
style="?android:attr/borderlessButtonStyle" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/deleteButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Delete"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
style="?android:attr/borderlessButtonStyle" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user