|
|
|
|
|
|
|
|
class DroidDropApp { |
|
|
constructor() { |
|
|
this.init(); |
|
|
} |
|
|
|
|
|
init() { |
|
|
this.setupEventListeners(); |
|
|
this.initializeComponents(); |
|
|
this.loadEmulators(); |
|
|
} |
|
|
|
|
|
setupEventListeners() { |
|
|
|
|
|
document.addEventListener('click', (e) => { |
|
|
if (e.target.closest('button') && e.target.closest('button').textContent.includes('Launch Emulator')) { |
|
|
this.handleEmulatorLaunch(e); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
document.addEventListener('click', (e) => { |
|
|
if (e.target.matches('a[href^="#"]')) { |
|
|
e.preventDefault(); |
|
|
const target = document.querySelector(e.target.getAttribute('href')); |
|
|
if (target) { |
|
|
target.scrollIntoView({ behavior: 'smooth' }); |
|
|
} |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
initializeComponents() { |
|
|
|
|
|
console.log('DroidDrop initialized'); |
|
|
} |
|
|
|
|
|
async loadEmulators() { |
|
|
try { |
|
|
|
|
|
const emulators = await this.fetchEmulators(); |
|
|
this.renderEmulators(emulators); |
|
|
} catch (error) { |
|
|
console.error('Failed to load emulators:', error); |
|
|
} |
|
|
} |
|
|
|
|
|
async fetchEmulators() { |
|
|
|
|
|
return [ |
|
|
{ |
|
|
id: 1, |
|
|
name: 'Pixel 6 Pro', |
|
|
androidVersion: 'Android 13', |
|
|
resolution: '1440x3120px', |
|
|
ram: '4GB', |
|
|
image: 'http://static.photos/technology/640x360/1', |
|
|
popular: true |
|
|
}, |
|
|
{ |
|
|
id: 2, |
|
|
name: 'Samsung Galaxy S23', |
|
|
androidVersion: 'Android 14', |
|
|
resolution: '1080x2340px', |
|
|
ram: '8GB', |
|
|
image: 'http://static.photos/technology/640x360/2', |
|
|
popular: false |
|
|
}, |
|
|
{ |
|
|
id: 3, |
|
|
name: 'OnePlus 11', |
|
|
androidVersion: 'Android 12', |
|
|
resolution: '1440x3216px', |
|
|
ram: '6GB', |
|
|
image: 'http://static.photos/technology/640x360/3', |
|
|
popular: false |
|
|
} |
|
|
]; |
|
|
} |
|
|
|
|
|
renderEmulators(emulators) { |
|
|
|
|
|
console.log('Emulators loaded:', emulators); |
|
|
} |
|
|
|
|
|
handleEmulatorLaunch(event) { |
|
|
const button = event.target.closest('button'); |
|
|
const card = button.closest('.bg-white'); |
|
|
const deviceName = card.querySelector('h3').textContent; |
|
|
|
|
|
|
|
|
const originalText = button.textContent; |
|
|
button.innerHTML = '<div class="loading-spinner mx-auto"></div>'; |
|
|
button.disabled = true; |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
button.innerHTML = originalText; |
|
|
button.disabled = false; |
|
|
|
|
|
|
|
|
this.showNotification(`Launching ${deviceName} emulator...`, 'success'); |
|
|
|
|
|
|
|
|
|
|
|
}, 2000); |
|
|
} |
|
|
|
|
|
showNotification(message, type = 'info') { |
|
|
|
|
|
const notification = document.createElement('div'); |
|
|
notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg z-50 transform transition-all duration-300 ${ |
|
|
type === 'success' ? 'bg-green-500 text-white' : |
|
|
type === 'error' ? 'bg-red-500 text-white' : |
|
|
'bg-blue-500 text-white' |
|
|
}`; |
|
|
notification.textContent = message; |
|
|
|
|
|
document.body.appendChild(notification); |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
notification.remove(); |
|
|
}, 3000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => { |
|
|
new DroidDropApp(); |
|
|
}); |
|
|
|
|
|
|
|
|
const utils = { |
|
|
formatDeviceName: (name) => { |
|
|
return name.replace(/\s+/g, '-').toLowerCase(); |
|
|
}, |
|
|
|
|
|
getRandomColor: () => { |
|
|
const colors = ['blue', 'purple', 'green', 'red', 'yellow']; |
|
|
return colors[Math.floor(Math.random() * colors.length)]; |
|
|
}, |
|
|
|
|
|
debounce: (func, wait) => { |
|
|
let timeout; |
|
|
return function executedFunction(...args) { |
|
|
const later = () => { |
|
|
clearTimeout(timeout); |
|
|
func(...args); |
|
|
}; |
|
|
clearTimeout(timeout); |
|
|
timeout = setTimeout(later, wait); |
|
|
}; |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
window.DroidDropApp = DroidDropApp; |
|
|
window.utils = utils; |