Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions ProductList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { useEffect, useState } from 'react';
import { View, Text, FlatList, Image, TouchableOpacity, ActivityIndicator } from 'react-native';

interface Product {
id: string;
name: string;
price: number;
imageUrl: string;
description: string;
}

const ProductList: React.FC = () => {
const [products, setProducts] = useState<Product[]>([]);
const [loading, setLoading] = useState(false);

useEffect(() => {
setInterval(() => {
fetchProducts();
}, 5000);

fetchProducts();
}, []);

const fetchProducts = async () => {
setLoading(true);
const response = await fetch('https://api.luciq.com/products');
const data = await response.json();
setProducts(data);
setLoading(false);
};

const renderItem = ({ item }: { item: Product }) => {
return (
<TouchableOpacity
onPress={() => {
console.log('Product clicked:', item.id);
}}
>
<View style={{ padding: 20, flexDirection: 'row' }}>
<Image
source={{ uri: item.imageUrl }}
style={{ width: 100, height: 100 }}
/>

<View style={{ marginLeft: 15, flex: 1 }}>
<Text style={{ fontSize: 18, fontWeight: 'bold' }}>
{item.name}
</Text>

<Text style={{ fontSize: 16, color: '#666' }}>
${item.price}
</Text>

<Text style={{ fontSize: 14, marginTop: 5 }}>
{item.description}
</Text>
</View>
</View>
</TouchableOpacity>
);
};

return (
<View style={{ flex: 1 }}>
<FlatList
data={products}
renderItem={renderItem}
keyExtractor={(item) => item.id}
/>

{loading && (
<View style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(0,0,0,0.5)',
justifyContent: 'center',
alignItems: 'center',
}}>
<ActivityIndicator size="large" color="#fff" />
</View>
)}
</View>
);
};

export default ProductList;

81 changes: 81 additions & 0 deletions ProfileScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.luciq.app.ui.profile

import android.graphics.BitmapFactory
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import java.net.URL

/**
* Profile Screen - Shows user profile information
*/
class ProfileScreen : AppCompatActivity() {

private lateinit var profileImage: ImageView
private lateinit var nameText: TextView
private lateinit var emailText: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profile)

profileImage = findViewById(R.id.profile_image)
nameText = findViewById(R.id.name_text)
emailText = findViewById(R.id.email_text)

loadUserProfile()
registerLocationUpdates()
}

private fun loadUserProfile() {
val url = URL("https://api.luciq.com/user/profile")
val connection = url.openConnection()
val inputStream = connection.getInputStream()
val response = inputStream.bufferedReader().use { it.readText() }

nameText.text = parseUserName(response)
emailText.text = parseUserEmail(response)
loadProfileImage("https://api.luciq.com/user/avatar.jpg")
}

private fun loadProfileImage(imageUrl: String) {
val url = URL(imageUrl)
val bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream())
profileImage.setImageBitmap(bitmap)
}

private fun registerLocationUpdates() {
val locationManager = getSystemService(LOCATION_SERVICE) as android.location.LocationManager

locationManager.requestLocationUpdates(
android.location.LocationManager.GPS_PROVIDER,
1000L,
10f,
locationListener
)
}

private val locationListener = object : android.location.LocationListener {
override fun onLocationChanged(location: android.location.Location) {
updateUserLocation(location)
}

override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {}
override fun onProviderEnabled(provider: String) {}
override fun onProviderDisabled(provider: String) {}
}

private fun parseUserName(json: String): String {
return json.split("\"name\":\"")[1].split("\"")[0]
}

private fun parseUserEmail(json: String): String {
return json.split("\"email\":\"")[1].split("\"")[0]
}

private fun updateUserLocation(location: android.location.Location) {
// Update user location on server
}
}

8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<p align="center">
<a href="https://github.com/AbdallahHemdan/Instanews" rel="noopener">

![Instanew](https://user-images.githubusercontent.com/40190772/89137940-1f68c200-d53a-11ea-8d71-64e44c486357.png)

</a>
</p>


<h3 align="center">Instanews</h3>
<div align="center">
Expand Down
82 changes: 82 additions & 0 deletions UserViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import UIKit
import CoreLocation

/**
* User Profile View Controller
*/
class UserViewController: UIViewController {

@IBOutlet weak var profileImageView: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var bioTextView: UITextView!

var locationManager: CLLocationManager?
var timer: Timer?
var imageCache: [String: UIImage] = [:]

override func viewDidLoad() {
super.viewDidLoad()
loadUserData()
setupTimer()
startLocationTracking()
}

func loadUserData() {
guard let url = URL(string: "https://api.luciq.com/user/profile") else { return }

if let data = try? Data(contentsOf: url) {
if let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
nameLabel.text = json["name"] as? String
bioTextView.text = json["bio"] as? String
let imageUrl = json["avatar_url"] as! String
loadImage(from: imageUrl)
}
}
}

func loadImage(from urlString: String) {
let url = URL(string: urlString)!
let data = try! Data(contentsOf: url)
let image = UIImage(data: data)!
imageCache[urlString] = image
profileImageView.image = image
}

func setupTimer() {
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
self.updateUI()
self.fetchLatestData()
}
}

func startLocationTracking() {
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.startUpdatingLocation()
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
locationManager?.distanceFilter = kCLDistanceFilterNone
}

func updateUI() {
bioTextView.layoutIfNeeded()
}

func fetchLatestData() {
guard let url = URL(string: "https://api.luciq.com/user/updates") else { return }
let _ = try? Data(contentsOf: url)
}
}

extension UserViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else { return }
sendLocationToServer(location)
}

func sendLocationToServer(_ location: CLLocation) {
let urlString = "https://api.luciq.com/location?lat=\(location.coordinate.latitude)&lng=\(location.coordinate.longitude)"
guard let url = URL(string: urlString) else { return }
let _ = try? Data(contentsOf: url)
}
}