Skip to content

Commit

Permalink
V0.0.1
Browse files Browse the repository at this point in the history
Base on the work, you can download the apk to use the app on Android
  • Loading branch information
Impre-visible committed Nov 24, 2022
1 parent 493a386 commit 9ffb5f5
Show file tree
Hide file tree
Showing 15 changed files with 11,754 additions and 3,898 deletions.
62 changes: 62 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,65 @@ web-build/

# macOS
.DS_Store

# @generated expo-cli sync-b25d41054229aa64f1468014f243adfae8268af2
# The following patterns were generated by expo-cli

# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# Bundle artifacts
*.jsbundle

# CocoaPods
/ios/Pods/

# Expo
.expo/
web-build/
dist/

# @end expo-cli
65 changes: 47 additions & 18 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import React from "react";
import Login from "./Login";
import OpenLink from "./OpenLink";
import { Alert } from "react-native";

export default function App() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
export default function Chocolate() {
const [url, setURL] = React.useState()
const [work, setWork] = React.useState(false)

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
console.log(url)

function loadChocolate() {

const regexExpurl = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
const regexExpIP = /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\:?([0-9]{1,5})?/

let regexWork = false;
let isChocolate = false;
let tempURL = url
if (tempURL.startsWith("http://") || tempURL.startsWith("https://")) {
tempURL = tempURL.replace("https://", "").replace("http://", "")
}
checkURL = `http://${tempURL}/isChocolate`
if (regexExpurl.test(tempURL) || regexExpIP.test(tempURL)) {
regexWork = true;
console.log("fetch -1")
fetch(checkURL).then(response => { console.log("response"+response); return response.json(); }).then(data => {
if (data.isChocolate) {
isChocolate = true;
} else {
Alert.alert("Chocolate", "This is not a Chocolate Server")
isChocolate = false;
}}).then(() => {
if (regexWork && isChocolate) {
setWork(true)
}}).catch((error) => {
Alert.alert("Chocolate Server Error", "This is not a Chocolate Server")
})
} else {
Alert.alert("Chocolate URL Error", "This is not a valid URL")
}
}

return (
<>
{!work ? <Login setURL={setURL} loadChocolate={loadChocolate} /> : <OpenLink url={url} />}
</>
);
}
48 changes: 48 additions & 0 deletions Login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { View, TextInput, TouchableOpacity, StatusBar, Text, StyleSheet } from "react-native"

export default function Login({ setURL, loadChocolate }) {
return (
<View style={styles.container}>
<TextInput placeholder="The Chocolate Server url"
style={styles.inputText}
onChangeText={(text) => setURL(text)} />
<TouchableOpacity style={styles.button} title="Connect" onPress={() => loadChocolate()}><Text style={styles.text}>TEST</Text></TouchableOpacity>
<StatusBar style="auto" />
</View>
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#1d1d1d',
alignItems: 'center',
justifyContent: 'center',
},
inputText: {
backgroundColor: '#9d9d9d40',
width: 250,
height: 42,
borderRadius: 10,
paddingLeft: 10,
outlineStyle: "none",
color: "white",
elevation: 5,
},
text: {
color: "white",
fontSize: 13,
},
button: {
marginTop: 44,
paddingTop: 30,
paddingBottom: 30,
paddingLeft: 40,
paddingRight: 40,
color: "white",
borderRadius: 22,
borderWidth: 1,
borderColor: '#fff',
elevation: 5,
}
});
19 changes: 19 additions & 0 deletions OpenLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { WebView } from 'react-native-webview';
import { Platform, View } from 'react-native';

export default function OpenLink({url}) {
return (
<View style={{flex: 1}}>
{ Platform.OS === 'web' ? (
<iframe width="100%" height="100%" src={url} frameborder="0"></iframe>)
:
(
<WebView
style={{flex: 1}}
originWhitelist={['*']}
javaScriptEnabled={true}
source={{ uri: url }} />
)}
</View>
);
}
68 changes: 37 additions & 31 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
{
"expo": {
"name": "chocolatemobileclient",
"slug": "chocolatemobileclient",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"web": {
"favicon": "./assets/favicon.png"
"expo": {
"name": "Chocolate",
"slug": "chocolatemobileclient",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/logo.png",
"userInterfaceStyle": "dark",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/logo.png",
"backgroundColor": "#FFFFFF"
},
"package": "com.imprevisible.chocolatemobileclient"
},
"web": {
"favicon": "./assets/logo.png"
},
"extra": {
"eas": {
"projectId": "1ec079ec-54ad-4921-934d-ffb0bcf2bea2"
}
}
}
}
}
}
Binary file removed assets/adaptive-icon.png
Binary file not shown.
Binary file removed assets/favicon.png
Binary file not shown.
Binary file removed assets/icon.png
Binary file not shown.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions eas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"build": {
"preview": {
"android": {
"buildType": "apk"
}
},
"preview2": {
"android": {
"gradleCommand": ":app:assembleRelease"
}
},
"preview3": {
"developmentClient": true
},
"production": {
"android": {
"buildType": "apk",
"gradleCommand": ":app:assembleRelease"
}
}
}
}
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerRootComponent } from 'expo';

import App from './App';

// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
4 changes: 4 additions & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

module.exports = getDefaultConfig(__dirname);
Loading

0 comments on commit 9ffb5f5

Please sign in to comment.