Skip to content

Commit

Permalink
use download manager, fix task details, change bottom nav,
Browse files Browse the repository at this point in the history
pretty buttons
  • Loading branch information
niwla23 committed Apr 28, 2021
1 parent 1959e24 commit 7057018
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 290 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ android {
applicationId "com.schulhack"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 12
versionName "1.4.3"
versionCode 14
versionName "1.5.1"
multiDexEnabled true
}

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ allprojects {
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
}
3 changes: 2 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Wed Mar 31 12:20:49 CEST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
6 changes: 6 additions & 0 deletions licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
"licenseUrl": "https://github.com/kmagiera/react-native-screens/raw/master/LICENSE",
"parents": "SchulHack"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/master-atul/react-native-download-manager",
"licenseUrl": "https://github.com/master-atul/react-native-download-manager/raw/master/LICENSE",
"parents": "SchulHack"
},
"[email protected]": {
"licenses": "MIT",
"repository": "https://github.com/oblador/react-native-vector-icons",
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"url": "https://gitlab.com/niwla23/schulhack/-/issues"
},
"scripts": {
"android": "UPDATE_SERVER_BASE_URL=http://192.168.178.82:8888 ENABLE_AUTO_UPDATE=true react-native run-android",
"android": "UPDATE_SERVER_BASE_URL=http://192.168.178.82:8000 ENABLE_AUTO_UPDATE=true react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"releaseAndroid:standalone": "cd android && UPDATE_SERVER_BASE_URL=https://schulhack.gitlab.io/update-server ENABLE_AUTO_UPDATE=true ./gradlew assembleRelease",
"releaseAndroid:testUpdates": "cd android && UPDATE_SERVER_BASE_URL=http://192.168.178.82:8000 ENABLE_AUTO_UPDATE=true ./gradlew assembleRelease",
"releaseAndroid:fdroid": "cd android && ./gradlew assembleRelease",
"clean": "cd android && ./gradlew clean"
},
Expand All @@ -43,7 +44,8 @@
"react-native-restart": "^0.0.20",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.16.1",
"react-native-vector-icons": "^7.1.0"
"react-native-vector-icons": "^7.1.0",
"rn-fetch-blob": "^0.12.0"
},
"devDependencies": {
"@babel/core": "^7.8.4",
Expand Down Expand Up @@ -71,4 +73,4 @@
"node"
]
}
}
}
9 changes: 6 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { Navigation } from './navigation'
import AsyncStorage from '@react-native-async-storage/async-storage';
import { UpdateOverlay } from './components/updateOverlay'
import axios from "axios"
import { Linking } from 'react-native';
import { Alert, Linking } from 'react-native';
import getSimpleVersionCode from './helpers/getSimpleVersionCode'


const App = () => {

const [theme, setTheme] = useState("dark")
Expand All @@ -25,6 +24,7 @@ const App = () => {
}
})


if (Boolean(process.env["ENABLE_AUTO_UPDATE"])) {
console.log("checking for updates")
const currentVersionCode = Number(DeviceInfo.getBuildNumber())
Expand Down Expand Up @@ -62,7 +62,10 @@ const App = () => {
}, []);

const acceptUpdate = () => {
Linking.openURL(updateUrl)
Alert.alert("Browser schließen", "Bitte schließe den Browser, bevor du das update runterlädst",[
{"text": "Hab ich gemacht", onPress: () => {Linking.openURL(updateUrl)}}
])

}


Expand Down
41 changes: 41 additions & 0 deletions src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
import { Text, StyleSheet, ViewStyle, TextStyle, Pressable } from 'react-native';
import React from 'react';
import { useTheme } from '../theme/themeprovider';


const Button = ({onPress, text}) => {
const { colors, isDark } = useTheme();

interface Style {
text: TextStyle;
background: ViewStyle
}
const styles = StyleSheet.create<Style>({
text: {
color: colors.background,
textAlign: "center",
fontWeight: "bold",
letterSpacing: 2,

},
background: {
backgroundColor: colors.primary,
padding: 8,
borderRadius: 8
}
});


return (
<Pressable style={styles.background} onPress={onPress}>
<Text style={styles.text}>
{text.toUpperCase()}
</Text>
</Pressable>
);


};

export default Button
16 changes: 10 additions & 6 deletions src/iservscrapping/iservScrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ export class IservScrapper {

}

getHeaders() {
return {
Cookie: this.cookies,
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Content-Type': 'application/x-www-form-urlencoded'
}
}

async _authenticated_request(path: String, responseType?: ResponseType, method?: Method, body?: Object) {
return new Promise((resolve, reject) => {
axios({
method: method || "get",
url: `${this.url}${path}`,
responseType: responseType,
headers: {
Cookie: this.cookies,
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Content-Type': 'application/x-www-form-urlencoded'
},
headers: this.getHeaders(),
data: body
})
.then(function (response) {
Expand Down Expand Up @@ -82,7 +86,7 @@ export class IservScrapper {
} else {
response = await this._authenticated_request("/iserv/exercise"); // fetch only current tasks
}

return parseTasksOverview(response.data)
}

Expand Down
28 changes: 28 additions & 0 deletions src/iservscrapping/iservWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import dayjs from "dayjs"
import relativeTIme from "dayjs/plugin/relativeTime"
import { relativeTime } from "dayjs/locale/*";
import { Task } from "./types";
import RNFetchBlob from "rn-fetch-blob"
var _ = require('lodash');
require('dayjs/locale/de')



dayjs.extend(relativeTIme)
dayjs.locale("de")

Expand Down Expand Up @@ -66,6 +68,32 @@ export class IservWrapper {

}

async downloadFile(path: string, title: string) {
await this.loadCookieOrLogin()
const fileUrl = this.iserv?.url + path;
const headers = this.iserv?.getHeaders();
const config = {
downloadTitle: title,
downloadDescription:
"Heruntergeladen von SchulHack",
saveAsName: title,
allowedInRoaming: true,
allowedInMetered: true,
showInDownloads: true,
};
let dirs = RNFetchBlob.fs.dirs
RNFetchBlob
.config({
path: dirs.DownloadDir + '/' + title,
addAndroidDownloads: {
useDownloadManager : true,
notification: true,
description: "Datei heruntergeladen von SchulHack"
}
})
.fetch('GET', fileUrl, headers)
}

async getSubstitutionPlan(isNextDay) {
const dayToPath = {
false: "/iserv/plan/show/raw/01-Vertreter Schüler heute/subst_001.htm",
Expand Down
25 changes: 11 additions & 14 deletions src/iservscrapping/parseTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,24 @@ export function parseTaskDetails(input: String, baseUrl: String): Object {
task.description = $($(".text-break-word")[0]).html().trim()

// get task type
if ($("#confirmation").length > 0) {
task.type = "confirmation"
// do nothing since we already now if it is done
} else if ($(".file-universal-upload-button").length > 0) {
if ($(".file-universal-upload-button").length > 0) {
task.type = "upload"
// TODO
} else {
} else if ($('form[name="submission"]').length > 0) {
task.type = "text"
// TODO
} else {
task.type = "confirmation"
}

// get provided files
task.providedFiles = []

$($(".table-condensed > tbody")[0]).children().each(function (_index: Number, file) {
$($('form[name="iserv_exercise_attachment"] > table > tbody')[0]).children().each(function (_index: Number, file) {
file = $(file)

var parsedFile: IservFile = {}
parsedFile.name = $(file.children()[1]).text().trim() // Title
parsedFile.size = $(file.children()[2]).text() // Size
parsedFile.url = baseUrl + $($($(file.children()[1]).children()[0])[0]).attr("href") // URL
parsedFile.url = $($($(file.children()[1]).children()[0])[0]).attr("href") // URL

parsedFile.type = "file"
task.providedFiles?.push(parsedFile)
Expand All @@ -128,25 +125,25 @@ export function parseTaskDetails(input: String, baseUrl: String): Object {
if (task.type === "upload") {
task.uploadedFiles = []
const tableIndex = task.providedFiles.length > 0 ? 1 : 0
$($(".table-condensed > tbody")[tableIndex]).children().each(function (_index, file) {
$($('form[name="iserv_exercise_element"] > table > tbody')[0]).children().each(function (_index, file) {
file = $(file)

var parsedFile: IservFile = {}
parsedFile.name = $(file.children()[1]).text().trim() // Title
parsedFile.url = baseUrl + $($(file.children()[1]).children()[0]).attr("href")// URL
parsedFile.url = $($(file.children()[1]).children()[0]).attr("href")// URL
parsedFile.size = $(file.children()[2]).text().trim() // Size
parsedFile.type = "file"
task.uploadedFiles?.push(parsedFile)
})
try {
task.feedbackText = $(".col-md-12 > .panel > .panel-body").html().trim()
task.feedbackText = $(".table-fixed-width > tbody > tr div.text-break-word").html().trim()
} catch {
task.feedbackText = undefined
}
} else if (task.type === "text") {
task.uploadedText = $(".col-md-12 > .panel > .panel-body").html().replace("Bearbeiten", "").trim()
task.uploadedText = $("#submission_text").text().trim()
try {
task.feedbackText = $(".col-md-6 > .panel > .panel-body").html().trim()
task.feedbackText = $(".table-fixed-width > tbody > tr div.text-break-word").html().trim()
} catch {
task.feedbackText = undefined
}
Expand Down
17 changes: 9 additions & 8 deletions src/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const AppNavigation: React.FC<Props> = (props) => {
alignContent: "center",
alignSelf: "center",
width: "100%",
padding: 8

}}>
{state.routes.map((route, index) => {
Expand Down Expand Up @@ -188,8 +189,8 @@ const AppNavigation: React.FC<Props> = (props) => {
if (index === 2) {

return (


<TouchableOpacity
key={index + "center"}
accessibilityRole="button"
Expand All @@ -208,14 +209,14 @@ const AppNavigation: React.FC<Props> = (props) => {
margin: 10,
marginRight: 25,
marginLeft: 25,
transform: [{ scale: 2.1 }, {translateY: -6}],
transform: [{ scale: 2.1 }, { translateY: -6 }],
borderColor: colors.background2,
borderWidth: 3
}}
>
<FontAwesome5 name={iconName} style={[styles.icon, {margin: 0}]}></FontAwesome5>
<FontAwesome5 name={iconName} style={[styles.icon, { margin: 0 }]}></FontAwesome5>
</TouchableOpacity>

);
} else {

Expand All @@ -230,9 +231,9 @@ const AppNavigation: React.FC<Props> = (props) => {
onLongPress={onLongPress}
style={{
flex: 1,
backgroundColor: isFocused ? colors.secondary : (isDark ? colors.background: colors.background2),
backgroundColor: isFocused ? colors.secondary : (isDark ? colors.background : colors.background2),
borderRadius: 16,
margin: 5
margin: 5,
}}
>
<FontAwesome5 name={iconName} style={styles.icon}></FontAwesome5>
Expand Down Expand Up @@ -326,7 +327,7 @@ export const Navigation: React.FC<Props> = (props) => {
};
return (
<NavigationContainer theme={Theme}>

<Stack.Navigator headerMode="none">
{stackContent}

Expand Down
8 changes: 6 additions & 2 deletions src/screens/substitutionplan.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"use strict"

import React, { useState, useEffect } from 'react';
import { Text, Switch, View, StyleSheet, ViewStyle, TextStyle, SectionList, Button, RefreshControl } from 'react-native';
import { Text, Switch, View, StyleSheet, ViewStyle, TextStyle, SectionList, RefreshControl, Pressable } from 'react-native';
import { useTheme } from '../theme/themeprovider';
import { PlanItem } from '../components/planitem';
import { ListError } from '../components/listError'
import { IservWrapper } from '../iservscrapping/iservWrapper';
import Button from '../components/button'


export default function SubstitutionScreen({ navigation }) {
Expand Down Expand Up @@ -189,7 +190,10 @@ export default function SubstitutionScreen({ navigation }) {

/>
<View style={{ marginBottom: 16 }}></View>
<Button onPress={() => navigation.navigate("Settings")} color={colors.primary} title="Einstellungen"></Button>
{/* <Pressable onPress={() => navigation.navigate("Settings")}>
<Text >EINSTELLUNGEN</Text>
</Pressable> */}
<Button text="EINSTELLUNGEN" onPress={() => navigation.navigate("Settings")}></Button>
</View>

</>
Expand Down
Loading

0 comments on commit 7057018

Please sign in to comment.