Skip to content

Commit

Permalink
New changes - Location sharing option added
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsuthakar committed Oct 29, 2018
1 parent 198572c commit d30834e
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 23 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ dependencies {
/*chatmessageview*/
implementation 'me.himanshusoni.chatmessageview:chat-message-view:1.0.3'


/*easypermissions*/
implementation 'pub.devrel:easypermissions:1.2.0'

/*gson*/
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

Expand All @@ -54,9 +58,6 @@ dependencies {
/*multidex*/
compile 'com.android.support:multidex:1.0.3'

/*easypermissions*/
implementation 'pub.devrel:easypermissions:1.2.0'

/*picasso*/
compile 'com.squareup.picasso:picasso:2.5.2'

Expand All @@ -66,6 +67,13 @@ dependencies {
/*EasyImage*/
compile 'com.github.jkwiecien:EasyImage:1.3.1'

implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-nearby:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'





}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
</intent-filter>
</activity>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDNmSE7xEYTKxPOXp1rkda67va-HTr_Mes" />

<activity
android:name=".chat.ChatActivity"
android:screenOrientation="portrait"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/chatapp/chat/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public class Chat {
@Expose
private Integer read;

@SerializedName("lat")
@Expose
private String lat;

@SerializedName("lat")
@Expose
private String lng;

public String getKey() {
return key;
}
Expand Down
100 changes: 80 additions & 20 deletions app/src/main/java/com/chatapp/chat/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@

import com.chatapp.MyApplication;
import com.chatapp.R;
import com.chatapp.util.MapModel;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
Expand Down Expand Up @@ -120,7 +126,9 @@ public class ChatActivity extends AppCompatActivity {
List<Chat> chatList = new ArrayList<>();

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault());
String uploaded_image_url ="";
String uploaded_image_url = "";
private static final int PLACE_PICKER_REQUEST = 123;


@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -181,10 +189,10 @@ public void onReceive(Context context, Intent intent) {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
String myText = etMessage.getText().toString().trim();
if (myText.length() > 0) {
sendMessage(myText);
}
String myText = etMessage.getText().toString().trim();
if (myText.length() > 0) {
sendMessage(myText);
}

handled = true;
}
Expand Down Expand Up @@ -215,14 +223,13 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
});

sender_id = MyApplication.sender;
receiver_id = MyApplication.receiver;
receiver_id = MyApplication.receiver;


mAdapter = new ChatMessageAdapter(this, chatList, senderAvatar);
mChatView.setAdapter(mAdapter);



myRef = database.getReference().child(chatPath);
childEventListener = myRef.addChildEventListener(new ChildEventListener() {
@Override
Expand Down Expand Up @@ -266,8 +273,6 @@ public void onCancelled(DatabaseError databaseError) {
});




}

@Override
Expand All @@ -277,23 +282,22 @@ protected void onResume() {
}



@OnClick({R.id.attachment, R.id.send_messsage})
public void onViewClicked(View view) {
switch (view.getId()) {

case R.id.attachment:

openAttachmentDialog();
openAttachmentDialog();

break;
case R.id.send_messsage:


String myText = etMessage.getText().toString().trim();
if (myText.length() > 0) {
sendMessage(myText);
}
String myText = etMessage.getText().toString().trim();
if (myText.length() > 0) {
sendMessage(myText);
}

break;

Expand Down Expand Up @@ -368,12 +372,12 @@ public void onComplete(@NonNull Task<Uri> task) {

progressBar.setIndeterminate(false);
}
}});
}
});

}



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

Expand All @@ -396,9 +400,53 @@ public void onCanceled(EasyImage.ImageSource source, int type) {
});


}
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(this, data);
if (place != null) {
LatLng latLng = place.getLatLng();
MapModel mapModel = new MapModel(latLng.latitude + "", latLng.longitude + "");

Toast.makeText(thisActivity, mapModel.getLatitude() + "", Toast.LENGTH_SHORT).show();

/* A Place object contains details about that place, such as its name, address
and phone number. Extract the name, address, phone number, place ID and place types.
*/
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
final CharSequence phone = place.getPhoneNumber();
final String placeId = place.getId();
String attribution = PlacePicker.getAttributions(data);
if (attribution == null) {
attribution = "";
}


String url = "https://maps.googleapis.com/maps/api/staticmap?center="+latLng.latitude+","+latLng.longitude+"&zoom=17&size=400x400&key=AIzaSyDNmSE7xEYTKxPOXp1rkda67va-HTr_Mes";


Log.d(TAG, "url: " + url);

// Print data to debug log
Log.d(TAG, "Place selected: " + placeId + " (" + name.toString() + ")");

Chat chat = new Chat();
chat.setSender(sender_id);
chat.setTimestamp(System.currentTimeMillis());
chat.setType("image");
chat.setUrl(String.valueOf(url));
chat.setReceiver(receiver_id);
chat.setRead(0);
myRef.push().setValue(chat);

// databaseReference.push().setValue(mapModel);
}
}
}


}


public String getMimeType(Uri uri) {
String mimeType = null;
Expand All @@ -415,7 +463,6 @@ public String getMimeType(Uri uri) {
}



@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

Expand Down Expand Up @@ -450,7 +497,7 @@ public void onBackPressed() {

private void openAttachmentDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
String[] animals = {"Camera", "Gallery"};
String[] animals = {"Camera", "Gallery", "Location"};
builder.setItems(animals, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand All @@ -470,6 +517,10 @@ public void onClick(DialogInterface dialog, int which) {
}
break;

case 2:
locationPlacesIntent();
break;

default:
break;
}
Expand All @@ -480,5 +531,14 @@ public void onClick(DialogInterface dialog, int which) {
}


private void locationPlacesIntent() {
try {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}

}

31 changes: 31 additions & 0 deletions app/src/main/java/com/chatapp/util/MapModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.chatapp.util;

public class MapModel {

private String latitude;
private String longitude;

public MapModel() {
}

public MapModel(String latitude, String longitude) {
this.latitude = latitude;
this.longitude = longitude;
}

public void setLatitude(String latitude) {
this.latitude = latitude;
}

public String getLatitude() {
return latitude;
}

public void setLongitude(String longitude) {
this.longitude = longitude;
}

public String getLongitude() {
return longitude;
}
}

0 comments on commit d30834e

Please sign in to comment.