Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Set icon app, create splash screen and more... #179

Closed
wants to merge 7 commits into from
Closed
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
9 changes: 7 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:icon="@drawable/icon"
android:allowBackup="false"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/icon" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/notification_color" />
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
Expand Down
25 changes: 23 additions & 2 deletions android/app/src/main/java/com/unichat/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
package com.unichat;

import com.facebook.react.ReactActivity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.graphics.Color;

public class MainActivity extends ReactActivity {

/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
* Returns the name of the main component registered from JavaScript. This is
* used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "Unichat";
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set the Android background to white after 8 seconds
// to fix the splashscreen flash when the keyboard is shown
new CountDownTimer(8000, 1000) {

public void onTick(long millisUntilFinished) {
}

public void onFinish() {
getWindow().getDecorView().setBackgroundColor(Color.WHITE);
}

}.start();
}
}
Binary file added android/app/src/main/res/drawable-hdpi/icon.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 added android/app/src/main/res/drawable-ldpi/icon.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 added android/app/src/main/res/drawable-mdpi/icon.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 added android/app/src/main/res/drawable-xhdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions android/app/src/main/res/drawable/background_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/primary" />
<item
android:width="200dp"
android:height="200dp"
android:drawable="@drawable/logo"
android:gravity="center"
/>
</layer-list>
Binary file added android/app/src/main/res/drawable/icon.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 added android/app/src/main/res/drawable/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 removed android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Binary file removed android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<color name="primary">#FFF</color>
<color name="notification_color">#007AFF</color>
</resources>
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">@drawable/background_splash</item>
<item name="android:statusBarColor">@color/primary</item>
</style>

</resources>
11 changes: 7 additions & 4 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ return (exports.sendPushNotification = functions.firestore
},
notification: {
title: contactName,
body: contentTranslated,
body: content,
sound: "default",
android_channel_id: "main-channel",
collapseKey: "unichat",
group: "unichat"
priority: "high",
icon: "icon",
android_channel_id: "unichat",
large_icon: "icon",
show_in_foreground: "true",
content_available: "true"
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Components/Chat/chatContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import getTime from "~/functions/getTime"
import Message from "../mensagem"

const Chat = props => {
const { messages } = props
const { messages, destUserUid } = props
return (
<View>
<FlatList
Expand All @@ -15,6 +15,8 @@ const Chat = props => {
renderItem={({ item }) => {
return (
<Message
chave={item.key}
destUserUid={destUserUid}
content={
item.source === "1" ? item.content : item.contentTranslated
}
Expand Down
84 changes: 70 additions & 14 deletions src/Components/mensagem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { PureComponent } from "react"
import { Svg, Path } from "react-native-svg"
import { View, Text, StyleSheet, TouchableOpacity, Alert } from "react-native"
import { moderateScale } from "react-native-size-matters"
import firebase from "react-native-firebase"

const styles = StyleSheet.create({
// Estilo para a mensagem do remetente
Expand Down Expand Up @@ -85,33 +86,88 @@ const styles = StyleSheet.create({
})

export default class Mensagem extends PureComponent {
constructor() {
super()
constructor(props) {
super(props)
this.state = {
chave: "",
content: "",
date: "",
source: "",
original: ""
}
const userUid = firebase.auth().currentUser.uid
const { destUserUid } = this.props
this.ref = firebase
.firestore()
.collection("users")
.doc(userUid)
.collection("conversas")
.doc(destUserUid)
.collection("messages")
}

componentDidMount() {
const { content, date, source, original } = this.props
const { chave, content, date, source, original } = this.props

this.setState({ content, date, source, original })
this.setState({ chave, content, date, source, original })
}

alterarIdioma = chave => {
const { content, original } = this.state
const translated = content
const noTranslated = original
this.ref
.doc(chave)
.get()
.then(doc => {
const { isChanged } = doc.data()
if (isChanged) {
this.ref.doc(chave).update({
content: translated,
contentTranslated: noTranslated,
isChanged: false
})
} else {
this.ref.doc(chave).update({
content: translated,
contentTranslated: noTranslated,
isChanged: true
})
}
this.setState({ content: noTranslated, original: translated })
})
}

verLinguaOriginal = () => {
const { original } = this.state
Alert.alert(
"Confirmar",
"Deseja ver a mensagem na linguagem original?",
[
{ text: "Sim", onPress: () => this.setState({ content: original }) },
{ text: "Não" }
],
{ cancelable: false }
)
const { chave } = this.state

this.ref
.doc(chave)
.get()
.then(doc => {
const { isChanged } = doc.data()
if (isChanged) {
Alert.alert(
"Confirmar",
"Deseja ver a tradução da mensagem?",
[
{ text: "Sim", onPress: () => this.alterarIdioma(chave) },
{ text: "Não" }
],
{ cancelable: false }
)
} else {
Alert.alert(
"Confirmar",
"Deseja ver a mensagem na linguagem original?",
[
{ text: "Sim", onPress: () => this.alterarIdioma(chave) },
{ text: "Não" }
],
{ cancelable: false }
)
}
})
}

render() {
Expand Down
5 changes: 3 additions & 2 deletions src/Screens/Chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ export default class Conversas extends Component {
content: newMessage.content,
date: newMessage.date,
contentTranslated: translated,
source: "2"
source: "2",
isChanged: false
})
.then(() => true)
.catch(error => error)
Expand Down Expand Up @@ -267,7 +268,7 @@ export default class Conversas extends Component {
status={status}
/>
<View style={styles.chatContainer}>
<ChatContainer messages={messages} />
<ChatContainer messages={messages} destUserUid={destUser.key}/>
</View>
<View style={styles.input}>
<ChatInput
Expand Down
58 changes: 41 additions & 17 deletions src/Screens/Conversas/conversas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
TouchableOpacity,
BackHandler,
Alert,
AppState
AppState,
StatusBar
} from "react-native"
import { ListItem, Icon } from "react-native-elements"
import LinearGradient from "react-native-linear-gradient"
Expand Down Expand Up @@ -40,19 +41,36 @@ export default class Conversas extends Component {
}

async componentDidMount() {
this.listener = this.ref.onSnapshot(async () => {
const username = await AsyncStorage.getItem("@username")
const profileImageUrl = await AsyncStorage.getItem("@profileImageUrl")
this.setState({ myName: username, myPicture: profileImageUrl })
})
const { navigation } = this.props
const { isSerchable } = this.state

const username = await AsyncStorage.getItem("@username")
const profileImageUrl = await AsyncStorage.getItem("@profileImageUrl")
this.setState({ myName: username, myPicture: profileImageUrl })

const channel = new firebase.notifications.Android.Channel(
"unichat",
"Unichat channel",
firebase.notifications.Android.Importance.Max
)
.setDescription("My app channel")
.setVibrationPattern([500])
.setLockScreenVisibility(firebase.notifications.Android.Visibility.Public)

firebase.notifications().android.createChannel(channel)

const notificationOpen = await firebase
.notifications()
.getInitialNotification()
if (notificationOpen) {
const { notification } = notificationOpen
const { conversaId } = notification.data
notification.android.setGroup("unichat")
notification.android.setPriority(
firebase.notifications.Android.Priority.High
)
notification.android.setChannelId("unichat")
notification.android.setVibrate([500])
this.ref
.collection("conversas")
.doc(conversaId)
Expand All @@ -63,35 +81,40 @@ export default class Conversas extends Component {
navigation.navigate("ChatScreen", { item })
})
}

this.ref.update({
online: true
})

NetInfo.isConnected.addEventListener(
"connectionChange",
this.handleConnectivityChange
)

AppState.addEventListener("change", this.handleAppStateChange)
BackHandler.addEventListener("hardwareBackPress", this.handleBackPress)
this.getData()
this.willBlur = navigation.addListener("willBlur", () => {
this.setState(prevState => ({
arrayholder: prevState.conversas,
isSerchable: false,
text: ""
}))
if (isSerchable)
this.setState(prevState => ({
arrayholder: prevState.conversas,
isSerchable: false,
text: ""
}))
})
}

componentWillUnmount() {
const { isSerchable } = this.state
BackHandler.removeEventListener("hardwareBackPress", this.handleBackPress)
this.unsubscribe()
this.listener()
this.willBlur.remove()
this.setState(prevState => ({
arrayholder: prevState.conversas,
isSerchable: false,
text: ""
}))
if (isSerchable)
this.setState(prevState => ({
arrayholder: prevState.conversas,
isSerchable: false,
text: ""
}))
}

handleConnectivityChange = isConnected => {
Expand Down Expand Up @@ -301,6 +324,7 @@ export default class Conversas extends Component {
)
return (
<View style={styles.container}>
<StatusBar backgroundColor="#FFF" barStyle="dark-content" />
{toolbar}
<FlatList
data={arrayholder}
Expand Down