Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Florianisme committed Mar 3, 2022
2 parents a63811a + e181263 commit fb31bc2
Show file tree
Hide file tree
Showing 36 changed files with 640 additions and 34 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: "$rootProject.projectDir/shared-build.gradle"

android {
defaultConfig {
versionCode 28
versionCode 33
wearAppUnbundled true
}
buildFeatures {
Expand All @@ -19,6 +19,7 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1'
implementation 'com.google.guava:guava:31.0.1-jre'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

def room_version = "2.4.1"
implementation "androidx.room:room-runtime:$room_version"
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Expand All @@ -22,13 +23,17 @@
</intent-filter>
</activity>
<activity
android:name=".ui.home.modify.AddDeviceActivity"
android:name=".ui.home.details.AddDeviceActivity"
android:label="@string/title_activity_add_device"
android:theme="@style/Theme.WakeOnLan.NoDrawerActivity" />
<activity
android:name=".ui.home.modify.EditDeviceActivity"
android:name=".ui.home.details.EditDeviceActivity"
android:label="@string/title_activity_edit_device"
android:theme="@style/Theme.WakeOnLan.NoDrawerActivity" />
<activity
android:name=".ui.home.details.AddNetworkScanDeviceActivity"
android:label="@string/title_activity_add_device"
android:theme="@style/Theme.WakeOnLan.NoDrawerActivity" />

<service
android:name=".quicksettings.DeviceOneTileService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ private void updateTileState() {
appDatabase = DatabaseInstanceManager.getInstance(this);
Optional<Device> optionalMachine = getMachineAtIndex(machineAtIndex());

Tile tile = super.getQsTile();

if (optionalMachine.isPresent()) {
Device device = optionalMachine.get();
this.device = device;

super.getQsTile().setLabel(device.name);
tile.setLabel(device.name);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
super.getQsTile().setSubtitle(getString(R.string.tile_subtitle));
tile.setSubtitle(getString(R.string.tile_subtitle));
}
super.getQsTile().setState(Tile.STATE_ACTIVE);
tile.setState(Tile.STATE_ACTIVE);
} else {
super.getQsTile().setLabel(getString(R.string.tile_no_device_found));
super.getQsTile().setState(Tile.STATE_UNAVAILABLE);
tile.setLabel(getString(R.string.tile_no_device_found));
tile.setState(Tile.STATE_UNAVAILABLE);
}
super.getQsTile().updateTile();
tile.updateTile();
}

private Optional<Device> getMachineAtIndex(int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void initializeNavController() {
}

private Set<Integer> getMenuIds() {
return Sets.newHashSet(R.id.deviceListFragment, R.id.backupFragment);
return Sets.newHashSet(R.id.deviceListFragment, R.id.backupFragment, R.id.networkScanFragment);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.florianisme.wakeonlan.ui.home.modify;
package de.florianisme.wakeonlan.ui.home.details;

import android.view.Menu;
import android.view.MenuItem;
Expand Down
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.florianisme.wakeonlan.ui.home.modify;
package de.florianisme.wakeonlan.ui.home.details;

import android.os.Bundle;
import android.view.Menu;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package de.florianisme.wakeonlan.ui.home.modify;
package de.florianisme.wakeonlan.ui.home.details;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand All @@ -21,10 +22,10 @@
import de.florianisme.wakeonlan.databinding.ActivityModifyDeviceBinding;
import de.florianisme.wakeonlan.persistence.AppDatabase;
import de.florianisme.wakeonlan.persistence.DatabaseInstanceManager;
import de.florianisme.wakeonlan.ui.home.modify.watcher.autocomplete.MacAddressAutocomplete;
import de.florianisme.wakeonlan.ui.home.modify.watcher.validator.IpAddressValidator;
import de.florianisme.wakeonlan.ui.home.modify.watcher.validator.MacValidator;
import de.florianisme.wakeonlan.ui.home.modify.watcher.validator.NameValidator;
import de.florianisme.wakeonlan.ui.home.details.watcher.autocomplete.MacAddressAutocomplete;
import de.florianisme.wakeonlan.ui.home.details.watcher.validator.IpAddressValidator;
import de.florianisme.wakeonlan.ui.home.details.watcher.validator.MacValidator;
import de.florianisme.wakeonlan.ui.home.details.watcher.validator.NameValidator;
import de.florianisme.wakeonlan.util.BroadcastHelper;

public abstract class ModifyDeviceActivity extends AppCompatActivity {
Expand All @@ -36,6 +37,7 @@ public abstract class ModifyDeviceActivity extends AppCompatActivity {
protected TextInputEditText deviceNameInput;
protected TextInputEditText deviceStatusIpInput;
protected TextInputEditText deviceBroadcastInput;
protected ImageButton broadcastAutofill;
protected MaterialAutoCompleteTextView devicePorts;

@Override
Expand All @@ -50,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
deviceNameInput = binding.device.deviceName;
deviceStatusIpInput = binding.device.deviceStatusIp;
deviceBroadcastInput = binding.device.deviceBroadcast;
broadcastAutofill = binding.device.broadcastAutofill;

setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand All @@ -62,12 +65,12 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void addAutofillClickHandler() {
binding.device.broadcastAutofill.setOnClickListener(new View.OnClickListener() {
broadcastAutofill.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Optional<InetAddress> broadcastAddress = BroadcastHelper.getBroadcastAddress();
broadcastAddress.ifPresent(inetAddress -> binding.device.deviceBroadcast.setText(inetAddress.getHostAddress()));
broadcastAddress.ifPresent(inetAddress -> deviceBroadcastInput.setText(inetAddress.getHostAddress()));
} catch (IOException e) {
Log.e(this.getClass().getName(), "Can not retrieve Broadcast Address", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.florianisme.wakeonlan.ui.home.modify.watcher.autocomplete;
package de.florianisme.wakeonlan.ui.home.details.watcher.autocomplete;

import android.text.Editable;
import android.text.TextWatcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.florianisme.wakeonlan.ui.home.modify.watcher.validator;
package de.florianisme.wakeonlan.ui.home.details.watcher.validator;

import android.widget.EditText;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.florianisme.wakeonlan.ui.home.modify.watcher.validator;
package de.florianisme.wakeonlan.ui.home.details.watcher.validator;

import android.widget.EditText;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.florianisme.wakeonlan.ui.home.modify.watcher.validator;
package de.florianisme.wakeonlan.ui.home.details.watcher.validator;

import android.widget.EditText;

Expand Down
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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.florianisme.wakeonlan.ui.home.modify.watcher.validator;
package de.florianisme.wakeonlan.ui.home.details.watcher.validator;

import android.text.Editable;
import android.text.TextWatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import de.florianisme.wakeonlan.persistence.models.DeviceStatus;
import de.florianisme.wakeonlan.status.DeviceStatusTester;
import de.florianisme.wakeonlan.status.PingDeviceStatusTester;
import de.florianisme.wakeonlan.ui.home.details.EditDeviceActivity;
import de.florianisme.wakeonlan.ui.home.list.DeviceClickedCallback;
import de.florianisme.wakeonlan.ui.home.modify.EditDeviceActivity;
import de.florianisme.wakeonlan.wol.WolSender;

public class DeviceItemViewHolder extends RecyclerView.ViewHolder {
Expand Down

This file was deleted.

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

0 comments on commit fb31bc2

Please sign in to comment.