-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
640 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lan/ui/home/modify/AddDeviceActivity.java → ...an/ui/home/details/AddDeviceActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/de/florianisme/wakeonlan/ui/home/details/AddNetworkScanDeviceActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.florianisme.wakeonlan.ui.home.details; | ||
|
||
import android.os.Bundle; | ||
|
||
public class AddNetworkScanDeviceActivity extends AddDeviceActivity { | ||
|
||
public static final String MACHINE_IP_KEY = "deviceIp"; | ||
public static final String MACHINE_NAME_KEY = "deviceName"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
prepopulateInputs(); | ||
} | ||
|
||
private void prepopulateInputs() { | ||
Bundle extras = getIntent().getExtras(); | ||
if (extras != null) { | ||
String machineName = extras.getString(MACHINE_NAME_KEY, null); | ||
String machineIp = extras.getString(MACHINE_IP_KEY, null); | ||
|
||
deviceNameInput.setText(machineName); | ||
deviceStatusIpInput.setText(machineIp); | ||
broadcastAutofill.callOnClick(); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...an/ui/home/modify/EditDeviceActivity.java → ...n/ui/home/details/EditDeviceActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../autocomplete/MacAddressAutocomplete.java → .../autocomplete/MacAddressAutocomplete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...watcher/validator/IpAddressValidator.java → ...watcher/validator/IpAddressValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...odify/watcher/validator/MacValidator.java → ...tails/watcher/validator/MacValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dify/watcher/validator/NameValidator.java → ...ails/watcher/validator/NameValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ain/java/de/florianisme/wakeonlan/ui/home/details/watcher/validator/ValidationResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.florianisme.wakeonlan.ui.home.details.watcher.validator; | ||
|
||
public enum ValidationResult { | ||
VALID, INVALID | ||
} |
2 changes: 1 addition & 1 deletion
2
...e/modify/watcher/validator/Validator.java → .../details/watcher/validator/Validator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
...main/java/de/florianisme/wakeonlan/ui/home/modify/watcher/validator/ValidationResult.java
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
app/src/main/java/de/florianisme/wakeonlan/ui/home/scan/NetworkScanAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package de.florianisme.wakeonlan.ui.home.scan; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.AsyncListDiffer; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import de.florianisme.wakeonlan.R; | ||
import de.florianisme.wakeonlan.ui.home.scan.model.NetworkScanDevice; | ||
import de.florianisme.wakeonlan.ui.home.scan.viewholder.EmptyViewHolder; | ||
import de.florianisme.wakeonlan.ui.home.scan.viewholder.ListViewType; | ||
import de.florianisme.wakeonlan.ui.home.scan.viewholder.ScanResultViewHolder; | ||
|
||
public class NetworkScanAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | ||
|
||
private final AsyncListDiffer<NetworkScanDevice> listDiffer = new AsyncListDiffer<>(this, new NetworkScanDiffCallback()); | ||
|
||
public void clearDataset() { | ||
listDiffer.submitList(new ArrayList<>()); | ||
} | ||
|
||
public void updateList(List<NetworkScanDevice> updatedList) { | ||
List<NetworkScanDevice> sortedList = updatedList.stream() | ||
.distinct() | ||
.sorted(getScanDeviceComparator()) | ||
.collect(Collectors.toList()); | ||
|
||
listDiffer.submitList(sortedList); | ||
} | ||
|
||
private Comparator<NetworkScanDevice> getScanDeviceComparator() { | ||
Comparator<NetworkScanDevice> networkScanDeviceComparator = | ||
Comparator.comparing(device -> | ||
Strings.nullToEmpty(device.getIpAddress()) | ||
.substring(0, device.getIpAddress() | ||
.lastIndexOf(".") + 1)); | ||
return networkScanDeviceComparator.reversed(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
View view; | ||
RecyclerView.ViewHolder viewHolder; | ||
|
||
if (ListViewType.EMPTY.ordinal() == viewType) { | ||
view = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.network_list_empty, parent, false); | ||
viewHolder = new EmptyViewHolder(view); | ||
} else { | ||
view = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.network_list_item, parent, false); | ||
viewHolder = new ScanResultViewHolder(view); | ||
} | ||
|
||
return viewHolder; | ||
} | ||
|
||
@Override | ||
public int getItemViewType(int position) { | ||
if (listDiffer.getCurrentList().isEmpty()) { | ||
return ListViewType.EMPTY.ordinal(); | ||
} else { | ||
return ListViewType.SCAN_DEVICE.ordinal(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { | ||
if (getItemViewType(position) == ListViewType.SCAN_DEVICE.ordinal()) { | ||
ScanResultViewHolder scanResultViewHolder = (ScanResultViewHolder) viewHolder; | ||
|
||
NetworkScanDevice networkScanDevice = listDiffer.getCurrentList().get(position); | ||
|
||
scanResultViewHolder.setNameIfPresent(networkScanDevice.getName()); | ||
scanResultViewHolder.setIpAddress(networkScanDevice.getIpAddress()); | ||
scanResultViewHolder.setOnAddClickListener(networkScanDevice); | ||
} | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
if (listDiffer.getCurrentList().isEmpty()) { | ||
return RecyclerView.NO_ID; | ||
} | ||
return listDiffer.getCurrentList().get(position).hashCode(); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
if (listDiffer.getCurrentList().isEmpty()) { | ||
return 1; // "Empty" item | ||
} | ||
return listDiffer.getCurrentList().size(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/de/florianisme/wakeonlan/ui/home/scan/NetworkScanDiffCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package de.florianisme.wakeonlan.ui.home.scan; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.DiffUtil; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import de.florianisme.wakeonlan.ui.home.scan.model.NetworkScanDevice; | ||
|
||
public class NetworkScanDiffCallback extends DiffUtil.ItemCallback<NetworkScanDevice> { | ||
|
||
@Override | ||
public boolean areItemsTheSame(@NonNull NetworkScanDevice oldItem, @NonNull NetworkScanDevice newItem) { | ||
return areContentsTheSame(oldItem, newItem); | ||
} | ||
|
||
@Override | ||
public boolean areContentsTheSame(@NonNull NetworkScanDevice oldItem, @NonNull NetworkScanDevice newItem) { | ||
return Strings.nullToEmpty(oldItem.getIpAddress()).equals(newItem.getIpAddress()) | ||
&& (oldItem.getName().isPresent() && newItem.getName().isPresent() && oldItem.getName().get().equals(newItem.getName().get())); | ||
} | ||
} |
Oops, something went wrong.