Notes
![]() ![]() Notes - notes.io |
import {
View,
Text,
TextInput,
TouchableOpacity,
StyleSheet,
ActivityIndicator,
Image,
Alert,
Keyboard,
ScrollView,
SafeAreaView,
TouchableWithoutFeedback,
Share,
Platform,
} from "react-native";
import * as FileSystem from "expo-file-system";
import * as MediaLibrary from "expo-media-library";
import useFetchMediaStore from "../stores/useFetchMediaStore";
import {
MaterialIcons,
Ionicons,
FontAwesome,
FontAwesome5,
} from "@expo/vector-icons";
import * as Clipboard from "expo-clipboard";
import * as SecureStore from "expo-secure-store";
import CryptoJS from "crypto-js"; // crypto-js kütüphanesini içe aktar
import { useNavigation } from "@react-navigation/native";
import {
AppOpenAd,
useRewardedAd,
TestIds,
AdEventType,
BannerAd,
BannerAdSize,
} from "react-native-google-mobile-ads";
const HomeScreen = () => {
const [url, setUrl] = useState(
"https://www.tiktok.com/@jlo/video/7349617698860436779"
);
const [downloadedMedia, setDownloadedMedia] = useState({});
const [isDownloading, setIsDownloading] = useState(false); // İndirme durumunu takip etmek için
const [pendingSaveToGalleryUri, setPendingSaveToGalleryUri] = useState(null); // Android için bekleyen URI
const [shouldShowAdForFetch, setShouldShowAdForFetch] = useState(false);
const [shouldShowAdForDownload, setShouldShowAdForDownload] = useState(false);
// Reklam aktif/pasif durumlarını kontrol eden state değişkenleri
const [isAppOpenAdActive, setIsAppOpenAdActive] = useState(false); // App Open Ad pasif
const [isFetchRewardAdActive, setIsFetchRewardAdActive] = useState(false); // Fetch Reward Ad pasif
const [isDownloadRewardAdActive, setIsDownloadRewardAdActive] =
useState(true); // Download Reward Ad aktif
const [isBannerAdActive, setIsBannerAdActive] = useState(false); // Banner Ad aktif
const { mediaData, medias, isLoading, error, fetchMedia, reset } =
useFetchMediaStore();
const navigation = useNavigation(); // Navigasyon için kullanılır
// AdMob reklam birimi ID'leri
const APP_OPEN_AD_UNIT_ID =
Platform.OS === "ios" ? TestIds.APP_OPEN : TestIds.APP_OPEN; // Gerçek ID'ler ile değiştirin
const REWARDED_AD_UNIT_ID =
Platform.OS === "ios" ? TestIds.REWARDED : TestIds.REWARDED; // Gerçek ID'ler ile değiştirin
const BANNER_AD_UNIT_ID =
Platform.OS === "ios" ? TestIds.BANNER : TestIds.BANNER; // Geliştirme için Test ID
// Rewarded Ad Hook
const {
isLoaded: rewardedAdLoaded,
isClosed: isRewardedAdClosed,
load: loadRewardedAd,
show: showRewardedAd,
} = useRewardedAd(REWARDED_AD_UNIT_ID, {
requestNonPersonalizedAdsOnly: true,
});
useEffect(() => {
// Rewarded Ad'i komponent yüklendiğinde yükle
loadRewardedAd();
}, [loadRewardedAd]);
useEffect(() => {
if (isRewardedAdClosed) {
// Reklam kapandıktan sonra yeni reklam yükle
loadRewardedAd();
// Reklam kapandıysa ve Android için kaydetme bekliyorsa kaydet
if (pendingSaveToGalleryUri) {
saveToGalleryAndroid(pendingSaveToGalleryUri);
setPendingSaveToGalleryUri(null);
}
}
}, [isRewardedAdClosed, loadRewardedAd, pendingSaveToGalleryUri]);
useEffect(() => {
const getPermission = async () => {
const { status } = await MediaLibrary.requestPermissionsAsync();
if (status !== "granted") {
Alert.alert(
"Permission Required",
"Storage permission is required to save files."
);
}
};
getPermission();
}, []);
// Home sayfası açıldıktan 1 saniye sonra App Open Ad göster
useEffect(() => {
if (!isAppOpenAdActive) return; // App Open Ad pasifse hiçbir şey yapma
const timeoutId = setTimeout(() => {
const appOpenAd = AppOpenAd.createForAdRequest(APP_OPEN_AD_UNIT_ID, {
requestNonPersonalizedAdsOnly: true,
});
const adListener = appOpenAd.addAdEventListener(
AdEventType.LOADED,
() => {
appOpenAd.show();
}
);
appOpenAd.load();
return () => {
adListener();
};
}, 1000); // 1 saniye gecikme
return () => {
clearTimeout(timeoutId);
};
}, [isAppOpenAdActive, APP_OPEN_AD_UNIT_ID]);
// Medya öğelerinin daha önce indirilip indirilmediğini kontrol eder
useEffect(() => {
const checkDownloadedMedia = async () => {
const newDownloadedMedia = {};
for (let mediaItem of medias) {
const key = CryptoJS.MD5(mediaItem.url).toString();
const cachedMedia = await SecureStore.getItemAsync(key);
if (cachedMedia) {
newDownloadedMedia[key] = true;
} else {
newDownloadedMedia[key] = false;
}
}
setDownloadedMedia(newDownloadedMedia);
};
if (medias.length > 0) {
checkDownloadedMedia();
} else {
setDownloadedMedia({});
}
}, [medias]);
// URL'den linki çıkarmak için yardımcı fonksiyon
const extractUrl = (text) => {
const urlMatch = text.match(/(https?://[^s]+)/g);
if (urlMatch && urlMatch.length > 0) {
return urlMatch[0];
}
return text;
};
// Android için galeriye kaydetme fonksiyonu
const saveToGalleryAndroid = async (fileUri) => {
try {
// Medya dosyasını galeride kaydet
const asset = await MediaLibrary.createAssetAsync(fileUri);
const albumName = "All Video Saver";
let album = await MediaLibrary.getAlbumAsync(albumName);
if (album == null) {
album = await MediaLibrary.createAlbumAsync(albumName, asset, false);
} else {
await MediaLibrary.addAssetsToAlbumAsync([asset], album, false);
}
Alert.alert("Success", "Media saved to gallery successfully.");
} catch (error) {
console.error("Error saving to gallery:", error);
Alert.alert("Error", "Failed to save media to gallery.");
}
};
const performDownload = async (mediaItem) => {
try {
// Medya URL'sini hashleyerek geçerli bir anahtar oluştur
const key = CryptoJS.MD5(mediaItem.url).toString();
// Medya daha önce indirilmiş mi kontrol et
const cachedMedia = await SecureStore.getItemAsync(key);
if (cachedMedia) {
// Medya daha önce indirildiyse, doğrudan paylaş
const fileUri = cachedMedia;
await Share.share({
url: fileUri,
});
return;
}
// İndirme işlemini başlat
setIsDownloading(true);
// Geçici dosya adı oluştur
const timestamp = Date.now();
const extension = mediaItem.extension || "mp4";
const tempFilename = `all_video_saver_${timestamp}.${extension}`;
const fileUri = `${FileSystem.documentDirectory}${tempFilename}`;
// Dosyayı indir
const downloadResult = await FileSystem.downloadAsync(
mediaItem.url,
fileUri
);
if (downloadResult.status !== 200) {
throw new Error("Failed to download the file.");
}
// İndirilen dosyayı doğrula
const fileInfo = await FileSystem.getInfoAsync(fileUri);
if (!fileInfo.exists || fileInfo.size === 0) {
throw new Error("Downloaded file is invalid.");
}
// İndirilen dosyanın URI'sini hashed anahtar ile SecureStore'da sakla
await SecureStore.setItemAsync(key, fileUri);
// downloadedMedia durumunu güncelle
setDownloadedMedia((prev) => ({ ...prev, [key]: true }));
if (Platform.OS === "android") {
// Android: Reklam aktifse, reklam gösterimini tetikle
if (isDownloadRewardAdActive) {
setPendingSaveToGalleryUri(fileUri);
setShouldShowAdForDownload(true);
showRewardedAd();
} else {
// Reklam pasifse, doğrudan galerilere kaydet
await saveToGalleryAndroid(fileUri);
}
} else if (Platform.OS === "ios") {
// iOS: Share API'si ile paylaş
Share.share({
url: fileUri,
message: "Check out this video!",
});
}
} catch (error) {
console.error("Error:", error);
Alert.alert("Error", error.message || "Failed to download the media.");
} finally {
// İndirme işlemi tamamlandı
setIsDownloading(false);
}
};
const performFetch = async (extractedUrl) => {
// Mevcut medya verilerini sıfırla
reset();
setDownloadedMedia({});
await fetchMedia(extractedUrl);
};
// Fetch için reklam gösterme fonksiyonu
const showAdForFetch = () => {
if (!isFetchRewardAdActive) return; // Fetch Reward Ad pasifse hiçbir şey yapma
setShouldShowAdForFetch(true);
};
// useEffect ile fetch reklamını göster
useEffect(() => {
if (!isFetchRewardAdActive) return; // Fetch Reward Ad pasifse hiçbir şey yapma
if (shouldShowAdForFetch && rewardedAdLoaded) {
showRewardedAd();
setShouldShowAdForFetch(false);
} else if (shouldShowAdForFetch && !rewardedAdLoaded) {
// Reklam yüklenmemişse, reklam yüklendiğinde göster
const loadAndShow = async () => {
await loadRewardedAd();
};
loadAndShow();
}
}, [
shouldShowAdForFetch,
rewardedAdLoaded,
loadRewardedAd,
showRewardedAd,
isFetchRewardAdActive,
]);
// useEffect ile download reklamını göster
useEffect(() => {
if (!isDownloadRewardAdActive) return; // Download Reward Ad pasifse hiçbir şey yapma
if (shouldShowAdForDownload && rewardedAdLoaded) {
showRewardedAd();
setShouldShowAdForDownload(false);
} else if (shouldShowAdForDownload && !rewardedAdLoaded) {
// Reklam yüklenmemişse, reklam yüklendiğinde göster
const loadAndShow = async () => {
await loadRewardedAd();
};
loadAndShow();
}
}, [
shouldShowAdForDownload,
rewardedAdLoaded,
loadRewardedAd,
showRewardedAd,
isDownloadRewardAdActive,
]);
const handleFetch = () => {
if (!url.trim()) {
Alert.alert("Error", "Please enter a valid URL.");
return;
}
// URL'den linki çıkar
const extractedUrl = extractUrl(url.trim());
setUrl(extractedUrl);
Keyboard.dismiss(); // Klavyeyi kapat
// Fetch işlemini başlat
performFetch(extractedUrl);
// Reklamı göstermek için tetikle
showAdForFetch();
};
const handleDownload = async (mediaItem) => {
await performDownload(mediaItem);
// Reklam durumu kontrolü performDownload içinde yapıldı
};
const handlePaste = async () => {
let clipboardContent = await Clipboard.getStringAsync();
if (clipboardContent) {
// Pasted content'ı işleyerek URL'yi çıkar
const extractedUrl = extractUrl(clipboardContent);
setUrl(extractedUrl);
} else {
Alert.alert("Clipboard is empty", "No content found in clipboard.");
}
};
const handleClear = () => {
setUrl("");
};
const handleReset = () => {
reset();
setUrl("");
setDownloadedMedia({});
};
// Hata mesajlarını düzgün bir şekilde göstermek için
const renderErrorMessage = (error) => {
try {
const errorObj = typeof error === "string" ? JSON.parse(error) : error;
if (errorObj.message) {
return errorObj.message;
} else if (errorObj.error) {
return errorObj.error;
} else {
return "An error occurred. Please try again.";
}
} catch (e) {
return error.toString();
}
};
// Uygulamayı tanıtan bir yazı ve platforma bağlı link ile paylaşım fonksiyonu
const handleAppShare = async () => {
const message = `Check out All Video Saver! Download videos from various platforms easily.nn`;
const shareUrl = "https://onelink.to/j79ddg";
try {
await Share.share({
message: message + shareUrl,
});
} catch (error) {
console.log(error);
}
};
// Desteklenen platform ikonlarını render eder
const renderSupportedPlatforms = () => (
<View style={styles.platformContainer}>
<Text style={styles.supportedText}>Supported Platforms</Text>
<View style={styles.platformIcons}>
{/* Her ikon, platformun renklerinde bir daire içinde gösterilir */}
<View
style={[styles.platformIconWrapper, { backgroundColor: "#E1306C" }]}>
<FontAwesome5 name="instagram" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#3b5998" }]}>
<FontAwesome5 name="facebook-f" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#1DA1F2" }]}>
<FontAwesome5 name="twitter" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#000000" }]}>
<FontAwesome5 name="tiktok" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#6441A5" }]}>
<FontAwesome5 name="twitch" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#34526f" }]}>
<FontAwesome5 name="tumblr" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#F5F20A" }]}>
<FontAwesome5 name="snapchat-ghost" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#E60023" }]}>
<FontAwesome5 name="pinterest-p" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#0077B5" }]}>
<FontAwesome5 name="linkedin-in" size={20} color="#fff" />
</View>
<View
style={[styles.platformIconWrapper, { backgroundColor: "#1ab7ea" }]}>
<FontAwesome5 name="vimeo-v" size={20} color="#fff" />
</View>
</View>
</View>
);
return (
<SafeAreaView style={styles.safeArea}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<ScrollView
style={styles.container}
keyboardShouldPersistTaps="handled">
{/* Üst menü */}
<View style={styles.header}>
<TouchableOpacity onPress={handleAppShare}>
<Ionicons name="share-social-outline" size={28} color="#4A4A4A" />
</TouchableOpacity>
<View style={styles.headerRight}>
<TouchableOpacity
onPress={() => {
// Premium sayfasına yönlendirme
navigation.navigate("Premium");
}}
style={styles.headerIcon}>
<FontAwesome name="diamond" size={28} color="#4A4A4A" />
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
// Ayarlar sayfasına yönlendirme
navigation.navigate("Settings");
}}
style={styles.headerIcon}>
<Ionicons name="settings-outline" size={28} color="#4A4A4A" />
</TouchableOpacity>
</View>
</View>
{/* Logo */}
<View style={styles.logoContainer}>
<Image
source={require("../assets/logo.png")} // Logonuzu buraya ekleyin
style={styles.logoImage}
/>
<Text style={styles.logoText}>All Video Saver</Text>
</View>
{/* Input ve Fetch Butonu */}
<View style={styles.inputContainer}>
<TextInput
style={styles.input}
placeholder="Enter the URL here..."
placeholderTextColor="#aaa"
value={url}
onChangeText={setUrl}
autoCapitalize="none"
autoCorrect={false}
keyboardType="url"
/>
{url.length > 0 ? (
<TouchableOpacity onPress={handleClear} style={styles.iconButton}>
<MaterialIcons name="clear" size={24} color="#888" />
</TouchableOpacity>
) : (
<TouchableOpacity onPress={handlePaste} style={styles.iconButton}>
<MaterialIcons name="content-paste" size={24} color="#888" />
</TouchableOpacity>
)}
<TouchableOpacity style={styles.fetchButton} onPress={handleFetch}>
<MaterialIcons name="arrow-forward-ios" size={20} color="white" />
</TouchableOpacity>
</View>
{/* Hata Mesajı */}
{error && (
<Text style={styles.errorText}>{renderErrorMessage(error)}</Text>
)}
{/* Yükleniyor Göstergesi */}
{isLoading && !isDownloading && (
<View style={styles.fetchingLoader}>
<ActivityIndicator size="large" color="#4A90E2" />
</View>
)}
{/* Medya İçeriği */}
{mediaData && !isLoading && (
<>
{/* Thumbnail */}
{mediaData.thumbnail && (
<Image
source={{ uri: mediaData.thumbnail }}
style={styles.mediaThumbnail}
/>
)}
{/* Medya Bilgisi */}
<View style={styles.mediaInfoContainer}>
{/* <Text style={styles.mediaTitle}>{mediaData.title}</Text> */}
{medias.map((item, index) => {
const key = CryptoJS.MD5(item.url).toString();
const isDownloaded = downloadedMedia[key];
return (
<React.Fragment key={index}>
<View style={styles.mediaItem}>
<Text style={styles.mediaDetails}>
{item.quality || "N/A"} | Size: {item.formattedSize}
</Text>
<TouchableOpacity
style={[
styles.downloadButton,
isDownloaded && styles.downloadedButton,
]}
onPress={() => handleDownload(item)}>
<MaterialIcons
name="file-download"
size={24}
color="white"
/>
</TouchableOpacity>
</View>
{isBannerAdActive &&
index === 0 && ( // İlk medya öğesinden sonra banner reklam göster
<View style={styles.bannerAdContainer}>
<BannerAd
unitId={BANNER_AD_UNIT_ID}
size={BannerAdSize.LARGE_BANNER}
requestOptions={{
requestNonPersonalizedAdsOnly: true,
}}
style={{ marginVertical: 20 }} // Reklam için isteğe bağlı stil
/>
</View>
)}
</React.Fragment>
);
})}
</View>
{/* Reset Butonu */}
<TouchableOpacity
style={styles.resetButton}
onPress={handleReset}>
<Text style={styles.resetButtonText}>Reset</Text>
</TouchableOpacity>
</>
)}
{/* Desteklenen Platformlar */}
{!isLoading && !mediaData && !error && renderSupportedPlatforms()}
</ScrollView>
</TouchableWithoutFeedback>
{/* İndirme sırasında Loading Indicator */}
{isDownloading && (
<View style={styles.downloadingOverlay}>
<ActivityIndicator size="large" color="#4A90E2" />
</View>
)}
</SafeAreaView>
);
};
// Android için galeriye kaydetme fonksiyonu
const saveToGalleryAndroid = async (fileUri) => {
try {
// Medya dosyasını galeride kaydet
const asset = await MediaLibrary.createAssetAsync(fileUri);
const albumName = "All Video Saver";
let album = await MediaLibrary.getAlbumAsync(albumName);
if (album == null) {
album = await MediaLibrary.createAlbumAsync(albumName, asset, false);
} else {
await MediaLibrary.addAssetsToAlbumAsync([asset], album, false);
}
Alert.alert("Success", "Media saved to gallery successfully.");
} catch (error) {
console.error("Error saving to gallery:", error);
Alert.alert("Error", "Failed to save media to gallery.");
}
};
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: "#FFFFFF",
},
header: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
paddingTop: Platform.OS === "android" ? 20 : 0,
},
headerRight: {
flexDirection: "row",
alignItems: "center",
},
headerIcon: {
marginLeft: 15,
},
container: {
flex: 1,
paddingHorizontal: 20,
paddingTop: 10,
},
logoContainer: {
alignItems: "center",
marginBottom: 20,
},
logoImage: {
width: 80,
height: 80,
resizeMode: "contain",
},
logoText: {
fontSize: 28,
fontWeight: "bold",
color: "#4A4A4A",
marginTop: 10,
},
inputContainer: {
flexDirection: "row",
alignItems: "center",
borderWidth: 1,
borderColor: "#CCCCCC",
borderRadius: 10,
backgroundColor: "#F7F7F7",
overflow: "hidden",
},
input: {
flex: 1,
height: 50,
paddingHorizontal: 10,
fontSize: 16,
color: "#333",
},
iconButton: {
padding: 10,
},
fetchButton: {
backgroundColor: "#4A90E2",
padding: 15,
},
errorText: {
color: "#D0021B",
marginTop: 10,
textAlign: "center",
},
fetchingLoader: {
marginTop: 20,
alignItems: "center",
},
mediaThumbnail: {
width: "100%",
height: 200,
resizeMode: "contain",
marginVertical: 20,
borderRadius: 10,
overflow: "hidden",
borderWidth: 1,
borderColor: "#CCCCCC",
},
mediaInfoContainer: {
width: "100%",
},
mediaTitle: {
fontSize: 20,
fontWeight: "bold",
marginBottom: 10,
textAlign: "center",
color: "#4A4A4A",
},
mediaItem: {
marginVertical: 5,
backgroundColor: "#FFFFFF",
padding: 15,
borderRadius: 10,
elevation: 2, // Android gölgelendirme
shadowColor: "#000", // iOS gölgelendirme
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.1,
shadowRadius: 2,
borderWidth: 1,
borderColor: "#EEEEEE",
},
mediaDetails: {
fontSize: 16,
color: "#4A4A4A",
marginBottom: 10,
},
downloadButton: {
alignItems: "center",
backgroundColor: "#7ED321",
paddingVertical: 12,
paddingHorizontal: 20,
justifyContent: "center",
borderRadius: 10,
},
downloadedButton: {
backgroundColor: "#F5A623", // Daha önce indirilen medya için farklı renk
},
resetButton: {
backgroundColor: "#D0021B",
paddingVertical: 15,
paddingHorizontal: 20,
borderRadius: 10,
alignItems: "center",
marginTop: 20,
alignSelf: "stretch",
},
resetButtonText: {
color: "white",
fontSize: 18,
fontWeight: "bold",
},
platformContainer: {
alignItems: "center",
marginTop: 30,
},
supportedText: {
fontSize: 18,
fontWeight: "bold",
marginBottom: 20,
color: "#4A4A4A",
},
platformIcons: {
flexDirection: "row",
flexWrap: "wrap",
justifyContent: "center",
},
platformIconWrapper: {
width: 50,
height: 50,
borderRadius: 25,
margin: 8,
justifyContent: "center",
alignItems: "center",
},
downloadingOverlay: {
position: "absolute",
top: 0,
left: 0,
right: 0,
// Alt kısmı (API yanıtları) kapatmaz
bottom: 0,
backgroundColor: "rgba(255, 255, 255, 0.5)",
justifyContent: "center",
alignItems: "center",
},
bannerAdContainer: {
marginVertical: 10,
alignItems: "center",
},
});
export default HomeScreen;
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team