From 6b1e1bcf2fe459fab2aae9de7508abc3266d9bd3 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 13 Oct 2019 11:46:24 +0530 Subject: [PATCH 1/3] Lynk Saver code push --- .DS_Store | Bin 0 -> 6148 bytes lynkhack | 1 + 2 files changed, 1 insertion(+) create mode 100644 .DS_Store create mode 160000 lynkhack diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0a8bc552d861c4d0b554550a6ddf3a134a22ebf2 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TZYp9Af<5lVTMsSu=Ol!x2X8_|4=S3NVuLY}HnnK2n0HW0o8vqpmkf?+O2b*t%;-oWDupUC8$LN3$*KivQ zdiOKg?D&ri(6^Hi!y_bc3tzrp5T^mg-h=x%>Sgu%hbR4Tsn%Ys9Mmk$Ut;0<_6J&!WRKe12@dTpEB?XDxy<1 literal 0 HcmV?d00001 diff --git a/lynkhack b/lynkhack new file mode 160000 index 00000000..86cb670c --- /dev/null +++ b/lynkhack @@ -0,0 +1 @@ +Subproject commit 86cb670c95599f87c5b44515e0d94ec89f8215d0 From ba0419877167ee6d8f8a2804f7c5475b81e5e3b5 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 13 Oct 2019 11:50:39 +0530 Subject: [PATCH 2/3] Lynk Saver code push --- lynkhack | 1 - lynkhack/.DS_Store | Bin 0 -> 6148 bytes lynkhack/LynkHack.iml | 19 + lynkhack/app/.gitignore | 1 + lynkhack/app/app.iml | 152 ++++++ lynkhack/app/build.gradle | 34 ++ lynkhack/app/google-services.json | 40 ++ lynkhack/app/proguard-rules.pro | 21 + .../com/lynkhack/ExampleInstrumentedTest.java | 27 ++ lynkhack/app/src/main/AndroidManifest.xml | 33 ++ .../main/java/com/lynkhack/ChatActivity.java | 204 ++++++++ .../java/com/lynkhack/DashboardActivity.java | 93 ++++ .../com/lynkhack/LocalDashWiFiDirect.java | 457 ++++++++++++++++++ .../main/java/com/lynkhack/MainActivity.java | 41 ++ .../src/main/java/com/lynkhack/MyAdapter.java | 135 ++++++ .../com/lynkhack/RequestHelpActivity.java | 101 ++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++ .../res/drawable/circle_button_drawable.xml | 9 + .../res/drawable/ic_launcher_background.xml | 170 +++++++ .../app/src/main/res/layout/activity_chat.xml | 68 +++ .../main/res/layout/activity_dashboard.xml | 33 ++ .../app/src/main/res/layout/activity_main.xml | 82 ++++ .../main/res/layout/activity_request_help.xml | 114 +++++ lynkhack/app/src/main/res/layout/cardview.xml | 57 +++ .../src/main/res/layout/chat_item_mine.xml | 19 + .../src/main/res/layout/chat_item_other.xml | 19 + .../main/res/layout/content_local_dash_wd.xml | 53 ++ .../app/src/main/res/layout/device_item.xml | 16 + .../app/src/main/res/layout/local_dash_wd.xml | 38 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes lynkhack/app/src/main/res/values/colors.xml | 6 + lynkhack/app/src/main/res/values/dimens.xml | 3 + lynkhack/app/src/main/res/values/strings.xml | 5 + lynkhack/app/src/main/res/values/styles.xml | 20 + .../java/com/lynkhack/ExampleUnitTest.java | 17 + lynkhack/build.gradle | 28 ++ lynkhack/gradle.properties | 20 + lynkhack/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + lynkhack/gradlew | 172 +++++++ lynkhack/gradlew.bat | 84 ++++ lynkhack/local.properties | 10 + lynkhack/settings.gradle | 2 + 54 files changed, 2453 insertions(+), 1 deletion(-) delete mode 160000 lynkhack create mode 100644 lynkhack/.DS_Store create mode 100644 lynkhack/LynkHack.iml create mode 100644 lynkhack/app/.gitignore create mode 100644 lynkhack/app/app.iml create mode 100644 lynkhack/app/build.gradle create mode 100644 lynkhack/app/google-services.json create mode 100644 lynkhack/app/proguard-rules.pro create mode 100644 lynkhack/app/src/androidTest/java/com/lynkhack/ExampleInstrumentedTest.java create mode 100644 lynkhack/app/src/main/AndroidManifest.xml create mode 100755 lynkhack/app/src/main/java/com/lynkhack/ChatActivity.java create mode 100644 lynkhack/app/src/main/java/com/lynkhack/DashboardActivity.java create mode 100755 lynkhack/app/src/main/java/com/lynkhack/LocalDashWiFiDirect.java create mode 100644 lynkhack/app/src/main/java/com/lynkhack/MainActivity.java create mode 100644 lynkhack/app/src/main/java/com/lynkhack/MyAdapter.java create mode 100644 lynkhack/app/src/main/java/com/lynkhack/RequestHelpActivity.java create mode 100644 lynkhack/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 lynkhack/app/src/main/res/drawable/circle_button_drawable.xml create mode 100644 lynkhack/app/src/main/res/drawable/ic_launcher_background.xml create mode 100755 lynkhack/app/src/main/res/layout/activity_chat.xml create mode 100644 lynkhack/app/src/main/res/layout/activity_dashboard.xml create mode 100644 lynkhack/app/src/main/res/layout/activity_main.xml create mode 100644 lynkhack/app/src/main/res/layout/activity_request_help.xml create mode 100644 lynkhack/app/src/main/res/layout/cardview.xml create mode 100755 lynkhack/app/src/main/res/layout/chat_item_mine.xml create mode 100755 lynkhack/app/src/main/res/layout/chat_item_other.xml create mode 100755 lynkhack/app/src/main/res/layout/content_local_dash_wd.xml create mode 100755 lynkhack/app/src/main/res/layout/device_item.xml create mode 100755 lynkhack/app/src/main/res/layout/local_dash_wd.xml create mode 100644 lynkhack/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 lynkhack/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 lynkhack/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 lynkhack/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 lynkhack/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 lynkhack/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 lynkhack/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 lynkhack/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 lynkhack/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 lynkhack/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 lynkhack/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 lynkhack/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 lynkhack/app/src/main/res/values/colors.xml create mode 100644 lynkhack/app/src/main/res/values/dimens.xml create mode 100644 lynkhack/app/src/main/res/values/strings.xml create mode 100644 lynkhack/app/src/main/res/values/styles.xml create mode 100644 lynkhack/app/src/test/java/com/lynkhack/ExampleUnitTest.java create mode 100644 lynkhack/build.gradle create mode 100644 lynkhack/gradle.properties create mode 100644 lynkhack/gradle/wrapper/gradle-wrapper.jar create mode 100644 lynkhack/gradle/wrapper/gradle-wrapper.properties create mode 100755 lynkhack/gradlew create mode 100644 lynkhack/gradlew.bat create mode 100644 lynkhack/local.properties create mode 100644 lynkhack/settings.gradle diff --git a/lynkhack b/lynkhack deleted file mode 160000 index 86cb670c..00000000 --- a/lynkhack +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 86cb670c95599f87c5b44515e0d94ec89f8215d0 diff --git a/lynkhack/.DS_Store b/lynkhack/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lynkhack/app/.gitignore b/lynkhack/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/lynkhack/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/lynkhack/app/app.iml b/lynkhack/app/app.iml new file mode 100644 index 00000000..08d88c68 --- /dev/null +++ b/lynkhack/app/app.iml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lynkhack/app/build.gradle b/lynkhack/app/build.gradle new file mode 100644 index 00000000..91d91316 --- /dev/null +++ b/lynkhack/app/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.lynkhack" + minSdkVersion 23 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.google.android.material:material:1.0.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + implementation 'com.android.support:cardview-v7:28.0.0' + implementation 'com.google.firebase:firebase-database:19.1.0' + implementation 'com.google.android.gms:play-services-location:17.0.0' + +} +apply plugin: 'com.google.gms.google-services' diff --git a/lynkhack/app/google-services.json b/lynkhack/app/google-services.json new file mode 100644 index 00000000..290778f8 --- /dev/null +++ b/lynkhack/app/google-services.json @@ -0,0 +1,40 @@ +{ + "project_info": { + "project_number": "119895911024", + "firebase_url": "https://lynksaver.firebaseio.com", + "project_id": "lynksaver", + "storage_bucket": "lynksaver.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:119895911024:android:9d071ef3ce2cc996dba2b5", + "android_client_info": { + "package_name": "com.lynkhack" + } + }, + "oauth_client": [ + { + "client_id": "119895911024-ghn7vnvopdmfkqads09ughu03s2d0qda.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyBiFOrO0nqFKRbFPiXO9hXdFZ7ssKlyHN8" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "119895911024-ghn7vnvopdmfkqads09ughu03s2d0qda.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/lynkhack/app/proguard-rules.pro b/lynkhack/app/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/lynkhack/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/lynkhack/app/src/androidTest/java/com/lynkhack/ExampleInstrumentedTest.java b/lynkhack/app/src/androidTest/java/com/lynkhack/ExampleInstrumentedTest.java new file mode 100644 index 00000000..1a0e0d64 --- /dev/null +++ b/lynkhack/app/src/androidTest/java/com/lynkhack/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.lynkhack; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.lynkhack", appContext.getPackageName()); + } +} diff --git a/lynkhack/app/src/main/AndroidManifest.xml b/lynkhack/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..32210fd4 --- /dev/null +++ b/lynkhack/app/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lynkhack/app/src/main/java/com/lynkhack/ChatActivity.java b/lynkhack/app/src/main/java/com/lynkhack/ChatActivity.java new file mode 100755 index 00000000..98de792f --- /dev/null +++ b/lynkhack/app/src/main/java/com/lynkhack/ChatActivity.java @@ -0,0 +1,204 @@ +package com.lynkhack; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; +import android.widget.TextView; + +import org.drulabs.localdash.model.ChatDTO; +import org.drulabs.localdash.notification.NotificationToast; +import org.drulabs.localdash.transfer.DataSender; +import org.drulabs.localdash.utils.ConnectionUtils; +import org.drulabs.localdash.utils.Utility; + +import java.util.ArrayList; +import java.util.List; + +public class ChatActivity extends AppCompatActivity { + + public static final String ACTION_CHAT_RECEIVED = "com.lynkhack"; + public static final String KEY_CHAT_DATA = "chat_data_key"; + + public static final String KEY_CHATTING_WITH = "chattingwith"; + public static final String KEY_CHAT_IP = "chatterip"; + public static final String KEY_CHAT_PORT = "chatterport"; + + EditText etChat; + RecyclerView chatListHolder; + private List chatList; + private ChatListAdapter chatListAdapter; + + private String chattingWith; + private String destIP; + private int destPort; + private String data =""; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_chat); + TextView chat= (TextView) findViewById(R.id.cardview_user_info); + initialize(); + chat.setText(data); + + chatListHolder = (RecyclerView) findViewById(R.id.chat_list); + etChat = (EditText) findViewById(R.id.et_chat_box); + + chatList = new ArrayList<>(); + chatListAdapter = new ChatListAdapter(chatList); + chatListHolder.setAdapter(chatListAdapter); + + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ChatActivity.this); + linearLayoutManager.setStackFromEnd(true); + chatListHolder.setLayoutManager(linearLayoutManager); + data = getIntent().getStringExtra("FROM_LYNK"); + sendUserDetails(data); + } + + private void initialize() { + IntentFilter filter = new IntentFilter(); + filter.addAction(ACTION_CHAT_RECEIVED); + LocalBroadcastManager.getInstance(ChatActivity.this).registerReceiver(chatReceiver, filter); + + Bundle extras = getIntent().getExtras(); + if (extras == null) { + NotificationToast.showToast(ChatActivity.this, "Invalid arguments to open chat"); + finish(); + } + + chattingWith = extras.getString(KEY_CHATTING_WITH); + destIP = extras.getString(KEY_CHAT_IP); + destPort = extras.getInt(KEY_CHAT_PORT); + + setToolBarTitle("Chat with " + chattingWith); + data = getIntent().getStringExtra("FROM_LYNK"); + + } + + + private void sendUserDetails(String message){ + + + ChatDTO myChat = new ChatDTO(); + myChat.setPort(ConnectionUtils.getPort(ChatActivity.this)); + myChat.setFromIP(Utility.getString(ChatActivity.this, "myip")); + myChat.setLocalTimestamp(System.currentTimeMillis()); + myChat.setMessage(message); + myChat.setSentBy(chattingWith); + myChat.setMyChat(true); + DataSender.sendChatInfo(ChatActivity.this, destIP, destPort, myChat); + +// chatListHolder.smoothScrollToPosition(chatList.size() - 1); + updateChatView(myChat); + } + + public void SendChatInfo(View v) { + String message = etChat.getText().toString(); + + ChatDTO myChat = new ChatDTO(); + myChat.setPort(ConnectionUtils.getPort(ChatActivity.this)); + myChat.setFromIP(Utility.getString(ChatActivity.this, "myip")); + myChat.setLocalTimestamp(System.currentTimeMillis()); + myChat.setMessage(message); + myChat.setSentBy(chattingWith); + myChat.setMyChat(true); + DataSender.sendChatInfo(ChatActivity.this, destIP, destPort, myChat); + + etChat.setText(""); +// chatListHolder.smoothScrollToPosition(chatList.size() - 1); + updateChatView(myChat); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + private BroadcastReceiver chatReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + switch (intent.getAction()) { + case ACTION_CHAT_RECEIVED: + ChatDTO chat = (ChatDTO) intent.getSerializableExtra(KEY_CHAT_DATA); + chat.setMyChat(false); + updateChatView(chat); + break; + default: + break; + } + } + }; + + private void updateChatView(ChatDTO chatObj) { + chatList.add(chatObj); + chatListAdapter.notifyDataSetChanged(); + chatListHolder.smoothScrollToPosition(chatList.size() - 1); + } + + private class ChatListAdapter extends RecyclerView.Adapter { + + private List chatList; + + ChatListAdapter(List chatList) { + this.chatList = chatList; + } + + @Override + public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if (viewType == 0) { + View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item_mine, + parent, false); + return new ChatHolder(itemView); + } else { + View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item_other, + parent, false); + return new ChatHolder(itemView); + } + } + + @Override + public void onBindViewHolder(ChatHolder holder, int position) { + holder.bind(chatList.get(position)); + } + + @Override + public int getItemCount() { + return chatList == null ? 0 : chatList.size(); + } + + @Override + public int getItemViewType(int position) { + ChatDTO chatObj = chatList.get(position); + return (chatObj.isMyChat() ? 0 : 1); + } + + class ChatHolder extends RecyclerView.ViewHolder { + TextView tvChatMessage; + + public ChatHolder(View itemView) { + super(itemView); + tvChatMessage = (TextView) itemView.findViewById(R.id.tv_chat_msg); + } + + public void bind(ChatDTO singleChat) { + tvChatMessage.setText(singleChat.getMessage()); + } + } + } + + private void setToolBarTitle(String title) { + if (getSupportActionBar() != null) { + getSupportActionBar().setTitle(title); + } + } +} diff --git a/lynkhack/app/src/main/java/com/lynkhack/DashboardActivity.java b/lynkhack/app/src/main/java/com/lynkhack/DashboardActivity.java new file mode 100644 index 00000000..65821746 --- /dev/null +++ b/lynkhack/app/src/main/java/com/lynkhack/DashboardActivity.java @@ -0,0 +1,93 @@ +package com.lynkhack; + +import android.location.Location; +import android.os.Bundle; + +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationServices; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.ValueEventListener; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.util.Log; +import android.view.View; +import android.widget.TextView; + +import org.w3c.dom.Text; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DashboardActivity extends AppCompatActivity { + + + RecyclerView recyclerView; + DatabaseReference mDatabase; + private RecyclerView.Adapter mAdapter; + FusedLocationProviderClient fusedLocationClient; + Location locationLocal; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_dashboard); + recyclerView = findViewById(R.id.recycler_dashboard); + mDatabase = FirebaseDatabase.getInstance().getReference(); + recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)); + fusedLocationClient = LocationServices.getFusedLocationProviderClient(this); + + fusedLocationClient.getLastLocation() + .addOnSuccessListener(this, new OnSuccessListener() { + @Override + public void onSuccess(Location location) { + // Got last known location. In some rare situations this can be null. + if (location != null) { + // Logic to handle location object + locationLocal = location; + } + } + }); + + mDatabase.child("users").addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(@NonNull DataSnapshot dataSnapshot) { +// DataSnapshot snapshot = (DataSnapshot) dataSnapshot.getValue(); +// snapshot.child(snapshot.getKey()).getValue(); + List> list = new ArrayList<>(); + for (DataSnapshot child : dataSnapshot.getChildren()) { + Log.d("Naveen",child.getValue().toString()); + Map g = (Map) dataSnapshot.child(child.getKey()).getValue(); +// String phone=g.get("Phone").toString(); +// String cat = g.get("category").toString(); + String location = g.get("username").toString(); + + list.add(g); + } + mAdapter = new MyAdapter(list,locationLocal,DashboardActivity.this); + recyclerView.setAdapter(mAdapter); + + } + + @Override + public void onCancelled(@NonNull DatabaseError databaseError) { + + } + }); + } + + + + +} diff --git a/lynkhack/app/src/main/java/com/lynkhack/LocalDashWiFiDirect.java b/lynkhack/app/src/main/java/com/lynkhack/LocalDashWiFiDirect.java new file mode 100755 index 00000000..48e59151 --- /dev/null +++ b/lynkhack/app/src/main/java/com/lynkhack/LocalDashWiFiDirect.java @@ -0,0 +1,457 @@ +package com.lynkhack; + +import android.Manifest; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.net.wifi.WpsInfo; +import android.net.wifi.p2p.WifiP2pConfig; +import android.net.wifi.p2p.WifiP2pDevice; +import android.net.wifi.p2p.WifiP2pDeviceList; +import android.net.wifi.p2p.WifiP2pInfo; +import android.net.wifi.p2p.WifiP2pManager; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.Snackbar; +import android.support.v4.app.FragmentTransaction; +import android.support.v4.content.LocalBroadcastManager; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import org.drulabs.localdash.db.DBAdapter; +import org.drulabs.localdash.model.DeviceDTO; +import org.drulabs.localdash.notification.NotificationToast; +import org.drulabs.localdash.transfer.DataHandler; +import org.drulabs.localdash.transfer.DataSender; +import org.drulabs.localdash.transfer.TransferConstants; +import org.drulabs.localdash.utils.ConnectionUtils; +import org.drulabs.localdash.utils.DialogUtils; +import org.drulabs.localdash.utils.Utility; +import org.drulabs.localdash.wifidirect.WiFiDirectBroadcastReceiver; + +import java.util.ArrayList; +import java.util.List; + +import androidx.appcompat.app.AppCompatActivity; + +public class LocalDashWiFiDirect extends AppCompatActivity implements PeerListFragment.OnListFragmentInteractionListener + , WifiP2pManager.PeerListListener, WifiP2pManager.ConnectionInfoListener { + + + + public static final String FIRST_DEVICE_CONNECTED = "first_device_connected"; + public static final String KEY_FIRST_DEVICE_IP = "first_device_ip"; + + private static final String WRITE_PERMISSION = Manifest.permission.WRITE_EXTERNAL_STORAGE; + private static final int WRITE_PERM_REQ_CODE = 19; + String datafromother = ""; + PeerListFragment deviceListFragment; + View progressBarLocalDash; + + WifiP2pManager wifiP2pManager; + WifiP2pManager.Channel wifip2pChannel; + WiFiDirectBroadcastReceiver wiFiDirectBroadcastReceiver; + private boolean isWifiP2pEnabled = false; + + private boolean isWDConnected = false; + + private AppController appController; +// private ConnectionListener connListener; + + /** + * @param isWifiP2pEnabled the isWifiP2pEnabled to set + */ + public void setIsWifiP2pEnabled(boolean isWifiP2pEnabled) { + this.isWifiP2pEnabled = isWifiP2pEnabled; + } + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.local_dash_wd); +// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); +// setSupportActionBar(toolbar); + + initialize(); + } + + private void initialize() { + + progressBarLocalDash = findViewById(R.id.progressBarLocalDash); + + String myIP = Utility.getWiFiIPAddress(LocalDashWiFiDirect.this); + Utility.saveString(LocalDashWiFiDirect.this, TransferConstants.KEY_MY_IP, myIP); + +// Starting connection listener with default for now +// connListener = new ConnectionListener(LocalDashWiFiDirect.this, TransferConstants.INITIAL_DEFAULT_PORT); +// connListener.start(); + + setToolBarTitle(0); + + wifiP2pManager = (WifiP2pManager) getSystemService(WIFI_P2P_SERVICE); + wifip2pChannel = wifiP2pManager.initialize(this, getMainLooper(), null); + + // Starting connection listener with default port for now + appController = (AppController) getApplicationContext(); + appController.startConnectionListener(TransferConstants.INITIAL_DEFAULT_PORT); + + checkWritePermission(); + datafromother = getIntent().getStringExtra("FROM_LYNK"); + +// findPeers(null); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_local_dash, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } + + public void findPeers(View v) { + + if (!isWDConnected) { + Snackbar.make(v, "Finding peers", Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + wifiP2pManager.discoverPeers(wifip2pChannel, new WifiP2pManager.ActionListener() { + @Override + public void onSuccess() { + NotificationToast.showToast(LocalDashWiFiDirect.this, "Peer discovery started"); + } + + @Override + public void onFailure(int reasonCode) { + NotificationToast.showToast(LocalDashWiFiDirect.this, "Peer discovery failure: " + + reasonCode); + } + }); + } + } + + @Override + protected void onPause() { +// if (mNsdHelper != null) { +// mNsdHelper.stopDiscovery(); +// } + LocalBroadcastManager.getInstance(this).unregisterReceiver(localDashReceiver); + unregisterReceiver(wiFiDirectBroadcastReceiver); + super.onPause(); + } + + @Override + protected void onResume() { + super.onResume(); + + IntentFilter localFilter = new IntentFilter(); + localFilter.addAction(DataHandler.DEVICE_LIST_CHANGED); + localFilter.addAction(FIRST_DEVICE_CONNECTED); + localFilter.addAction(DataHandler.CHAT_REQUEST_RECEIVED); + localFilter.addAction(DataHandler.CHAT_RESPONSE_RECEIVED); + LocalBroadcastManager.getInstance(LocalDashWiFiDirect.this).registerReceiver(localDashReceiver, + localFilter); + + IntentFilter wifip2pFilter = new IntentFilter(); + wifip2pFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); + wifip2pFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); + wifip2pFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); + wifip2pFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); + + wiFiDirectBroadcastReceiver = new WiFiDirectBroadcastReceiver(wifiP2pManager, + wifip2pChannel, this); + registerReceiver(wiFiDirectBroadcastReceiver, wifip2pFilter); + + LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DataHandler.DEVICE_LIST_CHANGED)); + } + + @Override + protected void onDestroy() { +// mNsdHelper.tearDown(); +// connListener.tearDown(); + appController.stopConnectionListener(); + Utility.clearPreferences(LocalDashWiFiDirect.this); + Utility.deletePersistentGroups(wifiP2pManager, wifip2pChannel); + DBAdapter.getInstance(LocalDashWiFiDirect.this).clearDatabase(); + wifiP2pManager.removeGroup(wifip2pChannel, new WifiP2pManager.ActionListener() { + @Override + public void onSuccess() { + + } + + @Override + public void onFailure(int i) { + + } + }); + + super.onDestroy(); + } + + private BroadcastReceiver localDashReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + switch (intent.getAction()) { + case FIRST_DEVICE_CONNECTED: +// connListener.tearDown(); +// int newPort = ConnectionUtils.getPort(LocalDashWiFiDirect.this); +// connListener = new ConnectionListener(LocalDashWiFiDirect.this, +// newPort); +// connListener.start(); +// appController.stopConnectionListener(); +// appController.startConnectionListener(ConnectionUtils.getPort(LocalDashWiFiDirect.this)); + appController.restartConnectionListenerWith(ConnectionUtils.getPort(LocalDashWiFiDirect.this)); + + String senderIP = intent.getStringExtra(KEY_FIRST_DEVICE_IP); + int port = DBAdapter.getInstance(LocalDashWiFiDirect.this).getDevice + (senderIP).getPort(); + DataSender.sendCurrentDeviceData(LocalDashWiFiDirect.this, senderIP, port, true); + isWDConnected = true; + break; + case DataHandler.DEVICE_LIST_CHANGED: + ArrayList devices = DBAdapter.getInstance(LocalDashWiFiDirect.this) + .getDeviceList(); + int peerCount = (devices == null) ? 0 : devices.size(); + if (peerCount > 0) { + progressBarLocalDash.setVisibility(View.GONE); + deviceListFragment = new PeerListFragment(); + Bundle args = new Bundle(); + args.putSerializable(PeerListFragment.ARG_DEVICE_LIST, devices); + deviceListFragment.setArguments(args); + + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.deviceListHolder, deviceListFragment); + ft.setTransition(FragmentTransaction.TRANSIT_NONE); + ft.commit(); + } + setToolBarTitle(peerCount); + break; + case DataHandler.CHAT_REQUEST_RECEIVED: + DeviceDTO chatRequesterDevice = (DeviceDTO) intent.getSerializableExtra(DataHandler + .KEY_CHAT_REQUEST); + DialogUtils.getChatRequestDialog(LocalDashWiFiDirect.this, + chatRequesterDevice).show(); + break; + case DataHandler.CHAT_RESPONSE_RECEIVED: + boolean isChatRequestAccepted = intent.getBooleanExtra(DataHandler + .KEY_IS_CHAT_REQUEST_ACCEPTED, false); + if (!isChatRequestAccepted) { + NotificationToast.showToast(LocalDashWiFiDirect.this, "Chat request " + + "rejected"); + } else { + DeviceDTO chatDevice = (DeviceDTO) intent.getSerializableExtra(DataHandler + .KEY_CHAT_REQUEST); + DialogUtils.openChatActivity(LocalDashWiFiDirect.this, chatDevice,datafromother); + NotificationToast.showToast(LocalDashWiFiDirect.this, chatDevice + .getPlayerName() + "Accepted Chat request"); + } + break; + default: + break; + } + } + }; + + private DeviceDTO selectedDevice; + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + switch (requestCode) { + case DialogUtils.CODE_PICK_IMAGE: + if (resultCode == RESULT_OK) { + Uri imageUri = data.getData(); + DataSender.sendFile(LocalDashWiFiDirect.this, selectedDevice.getIp(), + selectedDevice.getPort(), imageUri); + } + break; + default: + break; + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (grantResults[0] == PackageManager.PERMISSION_DENIED) { + finish(); + } + } + + private void checkWritePermission() { + boolean isGranted = Utility.checkPermission(WRITE_PERMISSION, this); + if (!isGranted) { + Utility.requestPermission(WRITE_PERMISSION, WRITE_PERM_REQ_CODE, this); + } + } + + boolean isConnectionInfoSent = false; + + @Override + public void onConnectionInfoAvailable(WifiP2pInfo wifiP2pInfo) { + + if (wifiP2pInfo.groupFormed && !wifiP2pInfo.isGroupOwner && !isConnectionInfoSent) { + + isWDConnected = true; + +// connListener.tearDown(); +// connListener = new ConnectionListener(LocalDashWiFiDirect.this, ConnectionUtils.getPort +// (LocalDashWiFiDirect.this)); +// connListener.start(); +// appController.stopConnectionListener(); +// appController.startConnectionListener(ConnectionUtils.getPort(LocalDashWiFiDirect.this)); + appController.restartConnectionListenerWith(ConnectionUtils.getPort(LocalDashWiFiDirect.this)); + + String groupOwnerAddress = wifiP2pInfo.groupOwnerAddress.getHostAddress(); + DataSender.sendCurrentDeviceDataWD(LocalDashWiFiDirect.this, groupOwnerAddress, TransferConstants + .INITIAL_DEFAULT_PORT, true); + isConnectionInfoSent = true; + } + } + + @Override + public void onPeersAvailable(WifiP2pDeviceList peerList) { + + ArrayList deviceDTOs = new ArrayList<>(); + + List devices = (new ArrayList<>()); + devices.addAll(peerList.getDeviceList()); + for (WifiP2pDevice device : devices) { + DeviceDTO deviceDTO = new DeviceDTO(); + deviceDTO.setIp(device.deviceAddress); + deviceDTO.setPlayerName(device.deviceName); + deviceDTO.setDeviceName(new String()); + deviceDTO.setOsVersion(new String()); + deviceDTO.setPort(-1); + deviceDTOs.add(deviceDTO); + } + + + progressBarLocalDash.setVisibility(View.GONE); + deviceListFragment = new PeerListFragment(); + Bundle args = new Bundle(); + args.putSerializable(PeerListFragment.ARG_DEVICE_LIST, deviceDTOs); + deviceListFragment.setArguments(args); + + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.deviceListHolder, deviceListFragment); + ft.setTransition(FragmentTransaction.TRANSIT_NONE); + ft.commit(); + } + + @Override + public void onListFragmentInteraction(final DeviceDTO deviceDTO) { + if (!isWDConnected) { + WifiP2pConfig config = new WifiP2pConfig(); + config.deviceAddress = deviceDTO.getIp(); + config.wps.setup = WpsInfo.PBC; + config.groupOwnerIntent = 4; + wifiP2pManager.connect(wifip2pChannel, config, new WifiP2pManager.ActionListener() { + @Override + public void onSuccess() { + // Connection request succeeded. No code needed here +// showServiceSelectionDialog(); +// DialogUtils.getServiceSelectionDialog(LocalDashWiFiDirect.this, deviceDTO).show(); + + } + + @Override + public void onFailure(int reasonCode) { + NotificationToast.showToast(LocalDashWiFiDirect.this, "Connection failed. try" + + " again: reason: " + reasonCode); + } + }); + } else { + selectedDevice = deviceDTO; +// showServiceSelectionDialog(); + DialogUtils.getServiceSelectionDialog(LocalDashWiFiDirect.this, deviceDTO).show(); + + } + } + + private void setToolBarTitle(int peerCount) { + if (getSupportActionBar() != null) { + String title = String.format(getString(R.string.wd_title_with_count), String + .valueOf(peerCount)); + getSupportActionBar().setTitle(title); + + } + } + + +// private void showChatRequestedDialog(final DeviceDTO device) { +// AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); +// +// String chatRequestTitle = getString(R.string.chat_request_title); +// chatRequestTitle = String.format(chatRequestTitle, device.getPlayerName() + "(" + device +// .getDeviceName() + ")"); +// alertDialog.setTitle(chatRequestTitle); +// String[] types = {"Accept", "Reject"}; +// alertDialog.setItems(types, new DialogInterface.OnClickListener() { +// +// @Override +// public void onClick(DialogInterface dialog, int which) { +// +// dialog.dismiss(); +// switch (which) { +// //Request accepted +// case 0: +// DialogUtils.openChatActivity(LocalDashWiFiDirect.this, device); +// NotificationToast.showToast(LocalDashWiFiDirect.this, "Chat request " + +// "accepted"); +// DataSender.sendChatResponse(LocalDashWiFiDirect.this, device.getIp(), +// device.getPort(), true); +// break; +// // Request rejected +// case 1: +// DataSender.sendChatResponse(LocalDashWiFiDirect.this, device.getIp(), +// device.getPort(), false); +// NotificationToast.showToast(LocalDashWiFiDirect.this, "Chat request " + +// "rejected"); +// break; +// } +// } +// +// }); +// +// alertDialog.show(); +// } + +// private void openChatActivity(DeviceDTO chatDevice) { +// Intent chatIntent = new Intent(LocalDashWiFiDirect.this, ChatActivity +// .class); +// chatIntent.putExtra(ChatActivity.KEY_CHAT_IP, chatDevice.getIp()); +// chatIntent.putExtra(ChatActivity.KEY_CHAT_PORT, chatDevice.getPort()); +// chatIntent.putExtra(ChatActivity.KEY_CHATTING_WITH, chatDevice.getPlayerName()); +// startActivity(chatIntent); +// } + + private void showServiceSelectionDialog() { + DataSender.sendChatRequest(LocalDashWiFiDirect.this, selectedDevice.getIp + (), selectedDevice.getPort()); + NotificationToast.showToast(LocalDashWiFiDirect.this, "chat request " + + "sent"); + + + } +} \ No newline at end of file diff --git a/lynkhack/app/src/main/java/com/lynkhack/MainActivity.java b/lynkhack/app/src/main/java/com/lynkhack/MainActivity.java new file mode 100644 index 00000000..119a482e --- /dev/null +++ b/lynkhack/app/src/main/java/com/lynkhack/MainActivity.java @@ -0,0 +1,41 @@ +package com.lynkhack; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.net.wifi.p2p.WifiP2pManager; +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity { + WifiP2pManager wifiP2pManager; + WifiP2pManager.Channel wifip2pChannel; + @Override + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + } + + + public void goToRequest(View view) { + + startActivity(new Intent(this,RequestHelpActivity.class)); + + } + + public void goToOfflineApp(View view) { + Intent i = getPackageManager().getLaunchIntentForPackage("org.drulabs.localdash"); + i.putExtra("FROM_LYNK","Connect with Naveen:8903877274"); + if (i!=null){ + startActivity(i); + } + + } + + public void dashboard(View view) { + startActivity(new Intent(MainActivity.this,DashboardActivity.class)); + } +} diff --git a/lynkhack/app/src/main/java/com/lynkhack/MyAdapter.java b/lynkhack/app/src/main/java/com/lynkhack/MyAdapter.java new file mode 100644 index 00000000..c22cf843 --- /dev/null +++ b/lynkhack/app/src/main/java/com/lynkhack/MyAdapter.java @@ -0,0 +1,135 @@ +package com.lynkhack; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.location.Location; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import com.google.firebase.database.ValueEventListener; + +import java.util.List; +import java.util.Map; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +public class MyAdapter extends RecyclerView.Adapter { + private List> mDataset; + private Location current_location; + Context context; + + // Provide a suitable constructor (depends on the kind of dataset) + public MyAdapter(List> list, Location locationLocal, Context context) { + mDataset = list; + current_location = locationLocal; + this.context = context; + } + + + @NonNull + @Override + public MyAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.cardview, parent, false); + + MyViewHolder vh = new MyViewHolder(v); + return vh; + } + + @Override + public void onBindViewHolder(MyViewHolder holder, int position) { + // - get element from your dataset at this position + // - replace the contents of the view with that element + + holder.name.setText(mDataset.get(position).get("username").toString()); + holder.status.setText(mDataset.get(position).get("Phone").toString()); + if (mDataset.get(position).get("lat") != null && mDataset.get(position).get("long") != null) { + holder.location.setText(mDataset.get(position).get("lat").toString() + " " + mDataset.get(position).get("long").toString()); + + + if (current_location != null) { + double cur_lat, cur_long; + double user_lat, user_long; + + cur_lat = current_location.getLatitude(); + cur_long = current_location.getLongitude(); + + user_lat = Double.parseDouble(mDataset.get(position).get("lat").toString()); + user_long = Double.parseDouble(mDataset.get(position).get("long").toString()); + + holder.mButtonConnectOffline.setVisibility(View.VISIBLE); + if (Math.round(distance(cur_lat,cur_long,user_lat,user_long)) <= 5){ + holder.mButtonConnectOffline.setText("Lynk ME!! with "+mDataset.get(position).get("username")); + holder.location.setText("Around "+Math.round(distance(cur_lat,cur_long,user_lat,user_long))+" mtr. You can connect with "+mDataset.get(position).get("username")+" offline"); + }else{ + holder.mButtonConnectOffline.setVisibility(View.GONE); + } + + + }else { + holder.mButtonConnectOffline.setVisibility(View.GONE); + } + + } else { + holder.location.setText("Location not available"); + holder.mButtonConnectOffline.setVisibility(View.GONE); + } + + holder.mButtonConnectOffline.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent i = context.getPackageManager().getLaunchIntentForPackage("org.drulabs.localdash"); + i.putExtra("FROM_LYNK","Connect with NGO NAVEEN:8903877274 "); + if (i!=null){ + context.startActivity(i); + } + } + }); + + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return mDataset.size(); + + } + + private double distance(double lat1, double lon1, double lat2, double lon2) { + double theta = lon1 - lon2; + double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)); + dist = Math.acos(dist); + dist = rad2deg(dist); + dist = dist * 60 * 1.1515; + return (dist); + } + + private double deg2rad(double deg) { + return (deg * Math.PI / 180.0); + } + + private double rad2deg(double rad) { + return (rad * 180.0 / Math.PI); + } + + class MyViewHolder extends RecyclerView.ViewHolder { + TextView name, location, status; + Button mButtonConnectOffline; + + public MyViewHolder(@NonNull View v) { + super(v); + name = v.findViewById(R.id.dashboard_name_custom_textview); + location = v.findViewById(R.id.dashboard_location_custom_textview); + status = v.findViewById(R.id.dashboard_status_custom_textview); + + mButtonConnectOffline = v.findViewById(R.id.dashboard_connect_offline_custom_button); + + } + } +} \ No newline at end of file diff --git a/lynkhack/app/src/main/java/com/lynkhack/RequestHelpActivity.java b/lynkhack/app/src/main/java/com/lynkhack/RequestHelpActivity.java new file mode 100644 index 00000000..c78cd0f9 --- /dev/null +++ b/lynkhack/app/src/main/java/com/lynkhack/RequestHelpActivity.java @@ -0,0 +1,101 @@ +package com.lynkhack; + +import android.content.Intent; +import android.location.Location; +import android.os.Bundle; + +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationServices; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import java.util.HashMap; +import java.util.Map; + +public class RequestHelpActivity extends AppCompatActivity { + private DatabaseReference mDatabase; + EditText name; + EditText phone; + String name_user; + String phone_num; + private FusedLocationProviderClient fusedLocationClient; + private Location locationLocal; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_request_help); + name = findViewById(R.id.editText); + phone = findViewById(R.id.editText2); + mDatabase = FirebaseDatabase.getInstance().getReference(); + fusedLocationClient = LocationServices.getFusedLocationProviderClient(this); + + fusedLocationClient.getLastLocation() + .addOnSuccessListener(this, new OnSuccessListener() { + @Override + public void onSuccess(Location location) { + // Got last known location. In some rare situations this can be null. + if (location != null) { + // Logic to handle location object + locationLocal = location; + } + } + }); + } + + + private void getuserData(String cat) { + name_user = name.getText().toString(); + phone_num = phone.getText().toString(); + Map payload = new HashMap<>(); + payload.put("username", name_user); + payload.put("Phone", phone_num); + payload.put("category", cat); + if (locationLocal != null) { + payload.put("lat", String.valueOf(locationLocal.getLatitude())); + payload.put("long", String.valueOf(locationLocal.getLongitude())); + } + mDatabase.child("users").child(phone_num).setValue(payload).addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Void aVoid) { + Toast.makeText(RequestHelpActivity.this, "Requested Successfully", Toast.LENGTH_SHORT).show(); + startActivity(new Intent(RequestHelpActivity.this,DashboardActivity.class)); + + } + + }); + + } + + public void requestHelp(View view) { + + + } + + public void rescue(View view) { + getuserData("rescue"); + } + + public void food(View view) { + getuserData("food"); + } + + public void medical(View view) { + getuserData("medical"); + } + + public void others(View view) { + getuserData("others"); + } +} diff --git a/lynkhack/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/lynkhack/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..1f6bb290 --- /dev/null +++ b/lynkhack/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/lynkhack/app/src/main/res/drawable/circle_button_drawable.xml b/lynkhack/app/src/main/res/drawable/circle_button_drawable.xml new file mode 100644 index 00000000..eedac3cf --- /dev/null +++ b/lynkhack/app/src/main/res/drawable/circle_button_drawable.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/lynkhack/app/src/main/res/drawable/ic_launcher_background.xml b/lynkhack/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..0d025f9b --- /dev/null +++ b/lynkhack/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lynkhack/app/src/main/res/layout/activity_chat.xml b/lynkhack/app/src/main/res/layout/activity_chat.xml new file mode 100755 index 00000000..c29e662a --- /dev/null +++ b/lynkhack/app/src/main/res/layout/activity_chat.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + diff --git a/lynkhack/app/src/main/res/layout/activity_dashboard.xml b/lynkhack/app/src/main/res/layout/activity_dashboard.xml new file mode 100644 index 00000000..3c50cbf5 --- /dev/null +++ b/lynkhack/app/src/main/res/layout/activity_dashboard.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/lynkhack/app/src/main/res/layout/activity_main.xml b/lynkhack/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..3ac90d67 --- /dev/null +++ b/lynkhack/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lynkhack/app/src/main/res/layout/activity_request_help.xml b/lynkhack/app/src/main/res/layout/activity_request_help.xml new file mode 100644 index 00000000..0fcdc637 --- /dev/null +++ b/lynkhack/app/src/main/res/layout/activity_request_help.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + +