Skip to content

Commit

Permalink
ColorScheme Correction Done
Browse files Browse the repository at this point in the history
  • Loading branch information
manupillai308 committed May 14, 2021
1 parent 2dcf1c2 commit ba2a272
Show file tree
Hide file tree
Showing 40 changed files with 416 additions and 90 deletions.
Binary file added android/app/src/main/assets/fonts/AntDesign.ttf
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/Entypo.ttf
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/EvilIcons.ttf
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/Feather.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/Fontisto.ttf
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/Foundation.ttf
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/Ionicons.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/Octicons.ttf
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added android/app/src/main/assets/fonts/Zocial.ttf
Binary file not shown.
35 changes: 23 additions & 12 deletions android/app/src/main/java/com/local_server/ClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.LinkedList;


public class ClientService extends Service {

public static Socket socket;
public static LinkedList<String> messages;
public static String IP_ADDRESS;
public static DataInputStream din;
public static DataOutputStream dout;
private static Context context;

private static final int SERVICE_NOTIFICATION_ID = 100100;

Expand All @@ -46,8 +50,7 @@ public static void stopClient(){
}
}

private boolean isAppOnForeground() {
Context context = getApplicationContext();
private static boolean isAppOnForeground() {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
Expand All @@ -72,13 +75,28 @@ public static void sendMsg(String msg){
stopClient();
}
}
public static void loadMsg(){
try{
while(isAppOnForeground()){
String msg = messages.pop();
WritableMap params = Arguments.createMap();
params.putString("payload", msg);
LocalServer.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("message",params);
}
}catch(NoSuchElementException e){

}catch(Exception e){}
}

private Runnable runnableCode = new Runnable() {

@Override
public void run() {
try{
// socket = new Socket(IP_ADDRESS, 6060);
messages = new LinkedList<String>();
context = getApplicationContext();
SocketAddress sockaddr = new InetSocketAddress(IP_ADDRESS, 6060);
socket = new Socket();
socket.connect(sockaddr, 3000);
Expand All @@ -105,16 +123,9 @@ public void run() {
LocalClient.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("message",params);
}
// else{
// Intent js_service = new Intent(context, HeadlessUpdateService.class);
// Bundle bundle = new Bundle();

// bundle.putString("payload", msg);
// js_service.putExtras(bundle);

// context.startService(js_service);
// HeadlessJsTaskService.acquireWakeLockNow(context);
// }
else{
ClientService.messages.add(msg);
}
}catch(SocketException e){
return;
}catch(IOException e){
Expand Down
74 changes: 65 additions & 9 deletions android/app/src/main/java/com/local_server/ServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import com.facebook.react.HeadlessJsTaskService;
import com.shhtalk.MainActivity;
import java.lang.Thread;
import java.text.SimpleDateFormat;
import java.net.*;
import java.io.*;
import java.util.*;
import java.nio.charset.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.LinkedList;
import java.lang.Thread;
Expand Down Expand Up @@ -53,14 +56,60 @@ class ClientConnection extends Thread{
data_out = new DataOutputStream(socket.getOutputStream());
write("{ \"user\": \"" + clientName + "\", \"title\": \"" + LocalServer.title + "\" }");

WritableMap params = Arguments.createMap();
params.putString("name", clientName);
params.putString("address", socket.getInetAddress().toString());
LocalServer.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
String msg = "{\"id\": \"" + getUniqueId() + "\", \"date\": \""+ getCurrentTime() + "\", \"type\":\"system\", \"message\": \"joined the chat\", \"user\": \"" + clientName + "\"}";
if(isAppOnForeground()){
WritableMap params = Arguments.createMap();
params.putString("name", clientName);
params.putString("address", socket.getInetAddress().toString());
LocalServer.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("client-connect", params);
}else{
ServerService.messages.add(msg);
}

ServerService.lock.lock();
ServerService.broadcastMsg(socket.getInetAddress().toString(), msg);
ServerService.lock.unlock();
exit = false;
}

static String getCurrentTime(){

SimpleDateFormat df = new SimpleDateFormat("HH:mm aa");
String currentTime = df.format(Calendar.getInstance().getTime());
return currentTime.replace("AM", "am").replace("PM","pm");
}

static String getUniqueId(){
byte[] array = new byte[256];
int n = 7;
new Random().nextBytes(array);

String randomString
= new String(array, Charset.forName("UTF-8"));

StringBuffer r = new StringBuffer();

String AlphaNumericString
= randomString
.replaceAll("[^A-Za-z0-9]", "");

for (int k = 0; k < AlphaNumericString.length(); k++) {

if (Character.isLetter(AlphaNumericString.charAt(k))
&& (n > 0)
|| Character.isDigit(AlphaNumericString.charAt(k))
&& (n > 0)) {

r.append(AlphaNumericString.charAt(k));
n--;
}
}
return r.toString();
}



public void write(String msg) throws IOException{
data_out.writeUTF(msg);
data_out.flush();
Expand Down Expand Up @@ -117,12 +166,19 @@ public void run(){
public void stopClient(){
exit = true;
try{

WritableMap params = Arguments.createMap();
params.putString("name", clientName);
params.putString("address", this.socket.getInetAddress().toString());
LocalServer.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
String msg = "{\"id\": \"" + getUniqueId() + "\", \"date\": \""+ getCurrentTime() + "\", \"type\":\"system\", \"message\": \"left the chat\", \"user\": \"" + clientName + "\"}";
if(isAppOnForeground()){
WritableMap params = Arguments.createMap();
params.putString("name", clientName);
params.putString("address", this.socket.getInetAddress().toString());
LocalServer.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("client-disconnect", params);
}else{
ServerService.messages.add(msg);
}
ServerService.lock.lock();
ServerService.broadcastMsg(this.socket.getInetAddress().toString(), msg);
ServerService.lock.unlock();

socket.close();
data_in.close();
Expand Down
5 changes: 5 additions & 0 deletions android/app/src/main/java/com/shhtalk/LocalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public void stopClient(){

}

@ReactMethod
public void loadMsg(){
ClientService.loadMsg();
}

@ReactMethod
public void sendMsg(String msg){
ClientService.sendMsg(msg);
Expand Down
Loading

0 comments on commit ba2a272

Please sign in to comment.