Skip to content

Commit

Permalink
Added activityIndicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazahir26 committed Apr 15, 2021
1 parent 65ac770 commit 68f8a05
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 103 deletions.
1 change: 0 additions & 1 deletion Context/ReminderDataContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ const notif = async (text, time) => {
// isAuthenticationRequired?: boolean,
opensAppToForeground: false,
},

},
];

Expand Down
25 changes: 1 addition & 24 deletions Context/SettingsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ const settings_reducer = (state, action) => {
};
storeData(data);
return data;
case "toggle_Snoozetime":
let tep = 30;
if (state.snoozetime == 30) {
tep = 45;
} else if (state.snoozetime == 45) {
tep = 60;
} else if (state.snoozetime == 60) {
tep = 30;
}
const data1 = {
...state,
snoozetime: tep,
};
storeData(data1);
return data1;
}
};

Expand All @@ -38,20 +23,13 @@ const toggle_darkmode = (dispatch) => {
};
};

const toggle_Snoozetime = (dispatch) => {
return () => {
dispatch({ type: "toggle_Snoozetime" });
};
};

const init_data_Settings = (dispatch) => {
return () => {
getData()
.then((value) => {
if (value == null) {
value = {
Theme: false,
snoozetime: 30,
};
}
dispatch({ type: "init_data", payload: value });
Expand Down Expand Up @@ -82,9 +60,8 @@ const getData = async () => {

export const { Context, Provider } = createDataContext(
settings_reducer,
{ toggle_darkmode, toggle_Snoozetime, init_data_Settings },
{ toggle_darkmode, init_data_Settings },
{
Theme: false,
snoozetime: 30,
}
);
16 changes: 1 addition & 15 deletions Screens/Settings_Screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Context } from "../Context/SettingsContext";
import { useTheme } from "react-native-paper";

function Settings() {
const { state, toggle_darkmode, toggle_Snoozetime } = useContext(Context);
const { state, toggle_darkmode } = useContext(Context);
const { colors } = useTheme();

return (
Expand Down Expand Up @@ -37,20 +37,6 @@ function Settings() {
/>
</TouchableOpacity>
</View>
<View
style={{
flexDirection: "row",
justifyContent: "space-between",
marginVertical: 15,
}}
>
<Text style={[styles.text, { color: colors.text }]}>Snooze Time</Text>
<TouchableOpacity onPress={toggle_Snoozetime}>
<Text style={[styles.text, { color: colors.text, fontSize: 20 }]}>
{state.snoozetime} mins
</Text>
</TouchableOpacity>
</View>
</View>
<View style={styles.TitleContainer}>
<Text style={[styles.text, { fontSize: 45, color: colors.text }]}>
Expand Down
132 changes: 69 additions & 63 deletions Screens/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, { useContext, useEffect } from "react";
import React, { useContext, useEffect, useState } from "react";
import Reminder_Screen from "./Reminder_Screen";
import Birthday_Screen from "./Birthday_Screen";
import Settings_Screen from "./Settings_Screen";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { NavigationContainer } from "@react-navigation/native";
import { AntDesign } from "@expo/vector-icons";
import { DefaultTheme, Provider as PaperProvider } from "react-native-paper";
import { View } from "react-native";
import {
DefaultTheme,
Provider as PaperProvider,
ActivityIndicator,
} from "react-native-paper";
import { Context as SettingsContext } from "../Context/SettingsContext";
import { Context as ReminderContext } from "../Context/ReminderDataContext";
import { Context as BirthdayContext } from "../Context/BirthdayDataContext";
import AsyncStorage from "@react-native-async-storage/async-storage";

import * as Notifications from "expo-notifications";
const lighttheme = {
Expand Down Expand Up @@ -47,7 +51,7 @@ function main() {
const { state, init_data_Settings } = useContext(SettingsContext);
var currentTheme = state.Theme ? lighttheme : darktheme;
const { colors } = currentTheme;

const [loading, setLoading] = useState(true);
useEffect(() => {
const subscription = Notifications.addNotificationResponseReceivedListener(
async (response) => {
Expand All @@ -56,22 +60,11 @@ function main() {
response.notification.request.content.categoryIdentifier ==
"reminder"
) {
try {
let jsonValue = await AsyncStorage.getItem("Settings-Data");
jsonValue = jsonValue != null ? JSON.parse(jsonValue) : null;
snooze({
text: response.notification.request.content.body,
val: response.notification.request.identifier,
snoozetime: jsonValue != null ? jsonValue.snoozetime : 30,
});
} catch (e) {
console.log(e);
snooze({
text: response.notification.request.content.body,
val: response.notification.request.identifier,
snoozetime: 30,
});
}
snooze({
text: response.notification.request.content.body,
val: response.notification.request.identifier,
snoozetime: 30,
});
}
}
await Notifications.dismissNotificationAsync(
Expand All @@ -86,51 +79,64 @@ function main() {
init_data();
init_data_Birthday();
init_data_Settings();
setTimeout(() => {
setLoading(false);
}, 500);
}, []);
return (
<PaperProvider theme={currentTheme}>
<NavigationContainer>
<Tab.Navigator
sceneContainerStyle={{ backgroundColor: colors.background }}
tabBarOptions={{
showLabel: false,
activeBackgroundColor: colors.tab,
inactiveBackgroundColor: colors.tab,
activeTintColor: colors.accent,
inactiveTintColor: colors.primary,
}}
>
<Tab.Screen
name="Reminder"
component={Reminder_Screen}
options={{
tabBarIcon: ({ size, color }) => (
<AntDesign name="clockcircleo" size={size} color={color} />
),
}}
/>
<Tab.Screen
name="Birthday"
component={Birthday_Screen}
options={{
tabBarIcon: ({ size, color }) => (
<AntDesign name="gift" size={size} color={color} />
),
}}
/>
<Tab.Screen
name="Settings"
component={Settings_Screen}
options={{
tabBarIcon: ({ size, color }) => (
<AntDesign name="setting" size={size} color={color} />
),

if (loading) {
return (
<View
style={{ flex: 1, justifyContent: "center", alignContent: "center" }}
>
<ActivityIndicator color="#7f2ee1" animating={true} size={40} />
</View>
);
} else
return (
<PaperProvider theme={currentTheme}>
<NavigationContainer>
<Tab.Navigator
sceneContainerStyle={{ backgroundColor: colors.background }}
tabBarOptions={{
showLabel: false,
activeBackgroundColor: colors.tab,
inactiveBackgroundColor: colors.tab,
activeTintColor: colors.accent,
inactiveTintColor: colors.primary,
}}
/>
</Tab.Navigator>
</NavigationContainer>
</PaperProvider>
);
>
<Tab.Screen
name="Reminder"
component={Reminder_Screen}
options={{
tabBarIcon: ({ size, color }) => (
<AntDesign name="clockcircleo" size={size} color={color} />
),
}}
/>
<Tab.Screen
name="Birthday"
component={Birthday_Screen}
options={{
tabBarIcon: ({ size, color }) => (
<AntDesign name="gift" size={size} color={color} />
),
}}
/>
<Tab.Screen
name="Settings"
component={Settings_Screen}
options={{
tabBarIcon: ({ size, color }) => (
<AntDesign name="setting" size={size} color={color} />
),
}}
/>
</Tab.Navigator>
</NavigationContainer>
</PaperProvider>
);
}

export default main;

0 comments on commit 68f8a05

Please sign in to comment.