-
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
27 changed files
with
188 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Java CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'adopt' | ||
- name: Build | ||
run: chmod +x ./gradlew && ./gradlew --parallel --max-workers=8 clean bundleDebug assembleDebug |
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
34 changes: 34 additions & 0 deletions
34
app/src/main/java/de/florianisme/wakeonlan/shortcuts/DeviceShortcutMapper.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,34 @@ | ||
package de.florianisme.wakeonlan.shortcuts; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.core.content.pm.ShortcutInfoCompat; | ||
import androidx.core.graphics.drawable.IconCompat; | ||
|
||
import de.florianisme.wakeonlan.R; | ||
import de.florianisme.wakeonlan.persistence.models.Device; | ||
|
||
public class DeviceShortcutMapper { | ||
|
||
public static ShortcutInfoCompat buildShortcut(Device device, Context context) { | ||
return new ShortcutInfoCompat.Builder(context, String.valueOf(device.id)) | ||
.setShortLabel(device.name) | ||
.setIntent(buildIntent(device, context)) | ||
.setIcon(IconCompat.createWithResource(context, R.drawable.device_shortcut)) | ||
.build(); | ||
} | ||
|
||
@NonNull | ||
private static Intent buildIntent(Device device, Context context) { | ||
Intent wakeDeviceIntent = new Intent(context, WakeDeviceActivity.class); | ||
wakeDeviceIntent.setAction(Intent.ACTION_VIEW); | ||
Bundle bundle = new Bundle(); | ||
bundle.putInt(WakeDeviceActivity.DEVICE_ID_KEY, device.id); | ||
wakeDeviceIntent.putExtras(bundle); | ||
return wakeDeviceIntent; | ||
} | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
app/src/main/java/de/florianisme/wakeonlan/shortcuts/DynamicShortcutManager.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,34 @@ | ||
package de.florianisme.wakeonlan.shortcuts; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
|
||
import androidx.core.content.pm.ShortcutManagerCompat; | ||
|
||
import java.util.List; | ||
|
||
import de.florianisme.wakeonlan.persistence.models.Device; | ||
|
||
public class DynamicShortcutManager { | ||
|
||
public void updateShortcuts(Context context, List<Device> devices) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) { | ||
return; | ||
} | ||
|
||
removeOldShortcuts(context); | ||
publishShortcuts(context, devices); | ||
} | ||
|
||
private void publishShortcuts(Context context, List<Device> devices) { | ||
devices.stream() | ||
.sorted((device1, device2) -> Integer.compare(device2.id, device1.id)) | ||
.map(device -> DeviceShortcutMapper.buildShortcut(device, context)) | ||
.forEach(shortcut -> ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)); | ||
} | ||
|
||
private void removeOldShortcuts(Context context) { | ||
ShortcutManagerCompat.removeAllDynamicShortcuts(context); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/de/florianisme/wakeonlan/shortcuts/WakeDeviceActivity.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,48 @@ | ||
package de.florianisme.wakeonlan.shortcuts; | ||
|
||
import android.os.Bundle; | ||
import android.widget.Toast; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import de.florianisme.wakeonlan.R; | ||
import de.florianisme.wakeonlan.persistence.models.Device; | ||
import de.florianisme.wakeonlan.persistence.repository.DeviceRepository; | ||
import de.florianisme.wakeonlan.wol.WolSender; | ||
|
||
public class WakeDeviceActivity extends AppCompatActivity { | ||
|
||
public static final String DEVICE_ID_KEY = "deviceId"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
wakeDevice(); | ||
finish(); | ||
} | ||
|
||
private void wakeDevice() { | ||
Bundle extras = getIntent().getExtras(); | ||
if (extras != null) { | ||
int machineId = extras.getInt(DEVICE_ID_KEY, -1); | ||
if (machineId == -1) { | ||
Toast.makeText(this, R.string.shortcut_wake_device_error, Toast.LENGTH_SHORT).show(); | ||
finish(); | ||
return; | ||
} | ||
|
||
Device device = DeviceRepository.getInstance(this).getById(machineId); | ||
|
||
if (!Strings.isNullOrEmpty(device.macAddress)) { | ||
WolSender.sendWolPacket(device); | ||
Toast.makeText(this, getString(R.string.wol_toast_sending_packet, device.name), Toast.LENGTH_LONG).show(); | ||
} else { | ||
Toast.makeText(this, R.string.shortcut_wake_device_error, Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="24dp" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M4,6h18L22,4L4,4c-1.1,0 -2,0.9 -2,2v11L0,17v3h14v-3L4,17L4,6zM23,8h-6c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h6c0.55,0 1,-0.45 1,-1L24,9c0,-0.55 -0.45,-1 -1,-1zM22,17h-4v-7h4v7z" /> | ||
</vector> |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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