org.telegram.ui.LocationActivity Java Examples

The following examples show how to use org.telegram.ui.LocationActivity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationActivityAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getItemCount() {
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP_VIEW) {
        return 2;
    } else if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
        return 2;
    } else if (currentMessageObject != null) {
        return 2 + (currentLiveLocations.isEmpty() ? 1 : currentLiveLocations.size() + 3);
    } else if (locationType == 2) {
        return 2 + currentLiveLocations.size();
    } else {
        if (searching || !searching && places.isEmpty()) {
            return (locationType != 0 ? 6 : 5) + (needEmptyView ? 1 : 0);
        }
        if (locationType == 1) {
            return 5 + places.size() + (places.isEmpty() ? 0 : 1) + (needEmptyView ? 1 : 0);
        } else {
            return 4 + places.size() + (places.isEmpty() ? 0 : 1) + (needEmptyView ? 1 : 0);
        }
    }
}
 
Example #2
Source File: LocationActivityAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getItemCount() {
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP_VIEW) {
        return 2;
    } else if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
        return 2;
    } else if (currentMessageObject != null) {
        return 2 + (currentLiveLocations.isEmpty() ? 1 : currentLiveLocations.size() + 3);
    } else if (locationType == 2) {
        return 2 + currentLiveLocations.size();
    } else {
        if (searching || !searching && places.isEmpty()) {
            return (locationType != 0 ? 6 : 5) + (needEmptyView ? 1 : 0);
        }
        if (locationType == 1) {
            return 5 + places.size() + (places.isEmpty() ? 0 : 1) + (needEmptyView ? 1 : 0);
        } else {
            return 4 + places.size() + (places.isEmpty() ? 0 : 1) + (needEmptyView ? 1 : 0);
        }
    }
}
 
Example #3
Source File: LocationActivityAdapter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public Object getItem(int i) {
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
        if (addressName == null) {
            return null;
        } else {
            TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue();
            venue.address = addressName;
            venue.geo = new TLRPC.TL_geoPoint();
            if (customLocation != null) {
                venue.geo.lat = customLocation.getLatitude();
                venue.geo._long = customLocation.getLongitude();
            } else if (gpsLocation != null) {
                venue.geo.lat = gpsLocation.getLatitude();
                venue.geo._long = gpsLocation.getLongitude();
            }
            return venue;
        }
    } else if (currentMessageObject != null) {
        if (i == 1) {
            return currentMessageObject;
        } else if (i > 4 && i < places.size() + 4) {
            return currentLiveLocations.get(i - 5);
        }
    } else if (locationType == 2) {
        if (i >= 2) {
            return currentLiveLocations.get(i - 2);
        }
        return null;
    } else if (locationType == 1) {
        if (i > 4 && i < places.size() + 5) {
            return places.get(i - 5);
        }
    } else {
        if (i > 3 && i < places.size() + 4) {
            return places.get(i - 4);
        }
    }
    return null;
}
 
Example #4
Source File: LocationActivityAdapter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void updateCell() {
    if (sendLocationCell != null) {
        if (locationType == LocationActivity.LOCATION_TYPE_GROUP || customLocation != null) {
            String address;
            if (!TextUtils.isEmpty(addressName)) {
                address = addressName;
            } else if (customLocation == null && gpsLocation == null || fetchingLocation) {
                address = LocaleController.getString("Loading", R.string.Loading);
            } else if (customLocation != null) {
                address = String.format(Locale.US, "(%f,%f)", customLocation.getLatitude(), customLocation.getLongitude());
            } else if (gpsLocation != null) {
                address = String.format(Locale.US, "(%f,%f)", gpsLocation.getLatitude(), gpsLocation.getLongitude());
            } else {
                address = LocaleController.getString("Loading", R.string.Loading);
            }
            if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
                sendLocationCell.setText(LocaleController.getString("ChatSetThisLocation", R.string.ChatSetThisLocation), address);
            } else {
                sendLocationCell.setText(LocaleController.getString("SendSelectedLocation", R.string.SendSelectedLocation), address);
            }
        } else {
            if (gpsLocation != null) {
                sendLocationCell.setText(LocaleController.getString("SendLocation", R.string.SendLocation), LocaleController.formatString("AccurateTo", R.string.AccurateTo, LocaleController.formatPluralString("Meters", (int) gpsLocation.getAccuracy())));
            } else {
                sendLocationCell.setText(LocaleController.getString("SendLocation", R.string.SendLocation), LocaleController.getString("Loading", R.string.Loading));
            }
        }
    }
}
 
Example #5
Source File: LocationActivityAdapter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setLiveLocations(ArrayList<LocationActivity.LiveLocation> liveLocations) {
    currentLiveLocations = new ArrayList<>(liveLocations);
    int uid = UserConfig.getInstance(currentAccount).getClientUserId();
    for (int a = 0; a < currentLiveLocations.size(); a++) {
        if (currentLiveLocations.get(a).id == uid) {
            currentLiveLocations.remove(a);
            break;
        }
    }
    notifyDataSetChanged();
}
 
Example #6
Source File: FragmentContextView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void openSharingLocation(final LocationController.SharingLocationInfo info) {
    if (info == null || fragment.getParentActivity() == null) {
        return;
    }
    LaunchActivity launchActivity = ((LaunchActivity) fragment.getParentActivity());
    launchActivity.switchToAccount(info.messageObject.currentAccount, true);

    LocationActivity locationActivity = new LocationActivity(2);
    locationActivity.setMessageObject(info.messageObject);
    final long dialog_id = info.messageObject.getDialogId();
    locationActivity.setDelegate((location, live, notify, scheduleDate) -> SendMessagesHelper.getInstance(info.messageObject.currentAccount).sendMessage(location, dialog_id, null, null, null, notify, scheduleDate));
    launchActivity.presentFragment(locationActivity);
}
 
Example #7
Source File: SharingLiveLocationCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setDialog(LocationActivity.LiveLocation info, Location userLocation) {
    liveLocation = info;
    int lower_id = info.id;
    if (lower_id > 0) {
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
        if (user != null) {
            avatarDrawable.setInfo(user);
            nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
            avatarImageView.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable,  user);
        }
    } else {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
        if (chat != null) {
            avatarDrawable.setInfo(chat);
            nameTextView.setText(chat.title);
            avatarImageView.setImage(ImageLocation.getForChat(chat, false), "50_50", avatarDrawable,  chat);
        }
    }

    GeoPoint position = info.marker.getPosition();
    location.setLatitude(position.getLatitude());
    location.setLongitude(position.getLongitude());

    String time = LocaleController.formatLocationUpdateDate(info.object.edit_date != 0 ? info.object.edit_date : info.object.date);
    if (userLocation != null) {
        distanceTextView.setText(String.format("%s - %s", time, LocaleController.formatDistance(location.distanceTo(userLocation))));
    } else {
        distanceTextView.setText(time);
    }
}
 
Example #8
Source File: LocationActivityAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void setLiveLocations(ArrayList<LocationActivity.LiveLocation> liveLocations) {
    currentLiveLocations = new ArrayList<>(liveLocations);
    int uid = UserConfig.getInstance(currentAccount).getClientUserId();
    for (int a = 0; a < currentLiveLocations.size(); a++) {
        if (currentLiveLocations.get(a).id == uid) {
            currentLiveLocations.remove(a);
            break;
        }
    }
    notifyDataSetChanged();
}
 
Example #9
Source File: LocationActivityAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public Object getItem(int i) {
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
        if (addressName == null) {
            return null;
        } else {
            TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue();
            venue.address = addressName;
            venue.geo = new TLRPC.TL_geoPoint();
            if (customLocation != null) {
                venue.geo.lat = customLocation.getLatitude();
                venue.geo._long = customLocation.getLongitude();
            } else if (gpsLocation != null) {
                venue.geo.lat = gpsLocation.getLatitude();
                venue.geo._long = gpsLocation.getLongitude();
            }
            return venue;
        }
    } else if (currentMessageObject != null) {
        if (i == 1) {
            return currentMessageObject;
        } else if (i > 4 && i < places.size() + 4) {
            return currentLiveLocations.get(i - 5);
        }
    } else if (locationType == 2) {
        if (i >= 2) {
            return currentLiveLocations.get(i - 2);
        }
        return null;
    } else if (locationType == 1) {
        if (i > 4 && i < places.size() + 5) {
            return places.get(i - 5);
        }
    } else {
        if (i > 3 && i < places.size() + 4) {
            return places.get(i - 4);
        }
    }
    return null;
}
 
Example #10
Source File: LocationActivityAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void updateCell() {
    if (sendLocationCell != null) {
        if (locationType == LocationActivity.LOCATION_TYPE_GROUP || customLocation != null) {
            String address;
            if (!TextUtils.isEmpty(addressName)) {
                address = addressName;
            } else if (customLocation == null && gpsLocation == null || fetchingLocation) {
                address = LocaleController.getString("Loading", R.string.Loading);
            } else if (customLocation != null) {
                address = String.format(Locale.US, "(%f,%f)", customLocation.getLatitude(), customLocation.getLongitude());
            } else if (gpsLocation != null) {
                address = String.format(Locale.US, "(%f,%f)", gpsLocation.getLatitude(), gpsLocation.getLongitude());
            } else {
                address = LocaleController.getString("Loading", R.string.Loading);
            }
            if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
                sendLocationCell.setText(LocaleController.getString("ChatSetThisLocation", R.string.ChatSetThisLocation), address);
            } else {
                sendLocationCell.setText(LocaleController.getString("SendSelectedLocation", R.string.SendSelectedLocation), address);
            }
        } else {
            if (gpsLocation != null) {
                sendLocationCell.setText(LocaleController.getString("SendLocation", R.string.SendLocation), LocaleController.formatString("AccurateTo", R.string.AccurateTo, LocaleController.formatPluralString("Meters", (int) gpsLocation.getAccuracy())));
            } else {
                sendLocationCell.setText(LocaleController.getString("SendLocation", R.string.SendLocation), LocaleController.getString("Loading", R.string.Loading));
            }
        }
    }
}
 
Example #11
Source File: LocationActivityAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setLiveLocations(ArrayList<LocationActivity.LiveLocation> liveLocations) {
    currentLiveLocations = new ArrayList<>(liveLocations);
    int uid = UserConfig.getInstance(currentAccount).getClientUserId();
    for (int a = 0; a < currentLiveLocations.size(); a++) {
        if (currentLiveLocations.get(a).id == uid) {
            currentLiveLocations.remove(a);
            break;
        }
    }
    notifyDataSetChanged();
}
 
Example #12
Source File: FragmentContextView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void openSharingLocation(final LocationController.SharingLocationInfo info)
{
    if (info == null || fragment.getParentActivity() == null)
    {
        return;
    }
    LaunchActivity launchActivity = ((LaunchActivity) fragment.getParentActivity());
    launchActivity.switchToAccount(info.messageObject.currentAccount, true);

    LocationActivity locationActivity = new LocationActivity(2);
    locationActivity.setMessageObject(info.messageObject);
    final long dialog_id = info.messageObject.getDialogId();
    locationActivity.setDelegate((location, live) -> SendMessagesHelper.getInstance(info.messageObject.currentAccount).sendMessage(location, dialog_id, null, null, null));
    launchActivity.presentFragment(locationActivity);
}
 
Example #13
Source File: SharingLiveLocationCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setDialog(LocationActivity.LiveLocation info, Location userLocation) {
    liveLocation = info;
    int lower_id = info.id;
    if (lower_id > 0) {
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
        if (user != null) {
            avatarDrawable.setInfo(user);
            nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
            avatarImageView.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable,  user);
        }
    } else {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
        if (chat != null) {
            avatarDrawable.setInfo(chat);
            nameTextView.setText(chat.title);
            avatarImageView.setImage(ImageLocation.getForChat(chat, false), "50_50", avatarDrawable,  chat);
        }
    }

    LatLng position = info.marker.getPosition();
    location.setLatitude(position.latitude);
    location.setLongitude(position.longitude);

    String time = LocaleController.formatLocationUpdateDate(info.object.edit_date != 0 ? info.object.edit_date : info.object.date);
    if (userLocation != null) {
        distanceTextView.setText(String.format("%s - %s", time, LocaleController.formatDistance(location.distanceTo(userLocation))));
    } else {
        distanceTextView.setText(time);
    }
}
 
Example #14
Source File: LocationActivityAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void setLiveLocations(ArrayList<LocationActivity.LiveLocation> liveLocations) {
    currentLiveLocations = new ArrayList<>(liveLocations);
    int uid = UserConfig.getInstance(currentAccount).getClientUserId();
    for (int a = 0; a < currentLiveLocations.size(); a++) {
        if (currentLiveLocations.get(a).id == uid) {
            currentLiveLocations.remove(a);
            break;
        }
    }
    notifyDataSetChanged();
}
 
Example #15
Source File: FragmentContextView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void openSharingLocation(final LocationController.SharingLocationInfo info)
{
    if (info == null || fragment.getParentActivity() == null)
    {
        return;
    }
    LaunchActivity launchActivity = ((LaunchActivity) fragment.getParentActivity());
    launchActivity.switchToAccount(info.messageObject.currentAccount, true);

    LocationActivity locationActivity = new LocationActivity(2);
    locationActivity.setMessageObject(info.messageObject);
    final long dialog_id = info.messageObject.getDialogId();
    locationActivity.setDelegate((location, live) -> SendMessagesHelper.getInstance(info.messageObject.currentAccount).sendMessage(location, dialog_id, null, null, null));
    launchActivity.presentFragment(locationActivity);
}
 
Example #16
Source File: FragmentContextView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void openSharingLocation(final LocationController.SharingLocationInfo info) {
    if (info == null || fragment.getParentActivity() == null) {
        return;
    }
    LaunchActivity launchActivity = ((LaunchActivity) fragment.getParentActivity());
    launchActivity.switchToAccount(info.messageObject.currentAccount, true);

    LocationActivity locationActivity = new LocationActivity(2);
    locationActivity.setMessageObject(info.messageObject);
    final long dialog_id = info.messageObject.getDialogId();
    locationActivity.setDelegate((location, live, notify, scheduleDate) -> SendMessagesHelper.getInstance(info.messageObject.currentAccount).sendMessage(location, dialog_id, null, null, null, notify, scheduleDate));
    launchActivity.presentFragment(locationActivity);
}
 
Example #17
Source File: LocationActivityAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemViewType(int position) {
    if (position == 0) {
        return 0;
    }
    if (needEmptyView && position == getItemCount() - 1) {
        return 10;
    }
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP_VIEW) {
        return 7;
    }
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
        return 1;
    }
    if (currentMessageObject != null) {
        if (currentLiveLocations.isEmpty()) {
            if (position == 2) {
                return 8;
            }
        } else {
            if (position == 2) {
                return 9;
            } else if (position == 3) {
                return 2;
            } else if (position == 4) {
                shareLiveLocationPotistion = position;
                return 6;
            }
        }
        return 7;
    }
    if (locationType == 2) {
        if (position == 1) {
            shareLiveLocationPotistion = position;
            return 6;
        } else {
            return 7;
        }
    }
    if (locationType == LocationActivity.LOCATION_TYPE_SEND_WITH_LIVE) {
        if (position == 1) {
            return 1;
        } else if (position == 2) {
            shareLiveLocationPotistion = position;
            return 6;
        } else if (position == 3) {
            return 9;
        } else if (position == 4) {
            return 2;
        } else if (searching || !searching && places.isEmpty()) {
            return 4;
        } else if (position == places.size() + 5) {
            return 5;
        }
    } else {
        if (position == 1) {
            return 1;
        } else if (position == 2) {
            return 9;
        } else if (position == 3) {
            return 2;
        } else if (searching || !searching && places.isEmpty()) {
            return 4;
        } else if (position == places.size() + 4) {
            return 5;
        }
    }
    return 3;
}
 
Example #18
Source File: LocationActivityAdapter.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemViewType(int position) {
    if (position == 0) {
        return 0;
    }
    if (needEmptyView && position == getItemCount() - 1) {
        return 10;
    }
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP_VIEW) {
        return 7;
    }
    if (locationType == LocationActivity.LOCATION_TYPE_GROUP) {
        return 1;
    }
    if (currentMessageObject != null) {
        if (currentLiveLocations.isEmpty()) {
            if (position == 2) {
                return 8;
            }
        } else {
            if (position == 2) {
                return 9;
            } else if (position == 3) {
                return 2;
            } else if (position == 4) {
                shareLiveLocationPotistion = position;
                return 6;
            }
        }
        return 7;
    }
    if (locationType == 2) {
        if (position == 1) {
            shareLiveLocationPotistion = position;
            return 6;
        } else {
            return 7;
        }
    }
    if (locationType == LocationActivity.LOCATION_TYPE_SEND_WITH_LIVE) {
        if (position == 1) {
            return 1;
        } else if (position == 2) {
            shareLiveLocationPotistion = position;
            return 6;
        } else if (position == 3) {
            return 9;
        } else if (position == 4) {
            return 2;
        } else if (searching || !searching && places.isEmpty()) {
            return 4;
        } else if (position == places.size() + 5) {
            return 5;
        }
    } else {
        if (position == 1) {
            return 1;
        } else if (position == 2) {
            return 9;
        } else if (position == 3) {
            return 2;
        } else if (searching || !searching && places.isEmpty()) {
            return 4;
        } else if (position == places.size() + 4) {
            return 5;
        }
    }
    return 3;
}
 
Example #19
Source File: SharingLiveLocationCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setDialog(LocationActivity.LiveLocation info, Location userLocation) {
    liveLocation = info;
    int lower_id = info.id;
    TLRPC.FileLocation photo = null;
    if (lower_id > 0) {
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
        avatarDrawable.setInfo(user);
        if (user != null) {
            nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
            if (user.photo != null && user.photo.photo_small != null) {
                photo = user.photo.photo_small;
            }
        }
    } else {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
        if (chat != null) {
            avatarDrawable.setInfo(chat);
            nameTextView.setText(chat.title);
            if (chat.photo != null && chat.photo.photo_small != null) {
                photo = chat.photo.photo_small;
            }
        }
    }

    LatLng position = info.marker.getPosition();
    location.setLatitude(position.latitude);
    location.setLongitude(position.longitude);

    String time = LocaleController.formatLocationUpdateDate(info.object.edit_date != 0 ? info.object.edit_date : info.object.date);
    if (userLocation != null) {
        float distance = location.distanceTo(userLocation);
        if (distance < 1000) {
            distanceTextView.setText(String.format("%s - %d %s", time, (int) (distance), LocaleController.getString("MetersAway", R.string.MetersAway)));
        } else {
            distanceTextView.setText(String.format("%s - %.2f %s", time, distance / 1000.0f, LocaleController.getString("KMetersAway", R.string.KMetersAway)));
        }
    } else {
        distanceTextView.setText(time);
    }

    avatarImageView.setImage(photo, null, avatarDrawable);
}
 
Example #20
Source File: SharingLiveLocationCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setDialog(LocationActivity.LiveLocation info, Location userLocation) {
    liveLocation = info;
    int lower_id = info.id;
    TLRPC.FileLocation photo = null;
    if (lower_id > 0) {
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
        avatarDrawable.setInfo(user);
        if (user != null) {
            nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
            if (user.photo != null && user.photo.photo_small != null) {
                photo = user.photo.photo_small;
            }
        }
    } else {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
        if (chat != null) {
            avatarDrawable.setInfo(chat);
            nameTextView.setText(chat.title);
            if (chat.photo != null && chat.photo.photo_small != null) {
                photo = chat.photo.photo_small;
            }
        }
    }

    LatLng position = info.marker.getPosition();
    location.setLatitude(position.latitude);
    location.setLongitude(position.longitude);

    String time = LocaleController.formatLocationUpdateDate(info.object.edit_date != 0 ? info.object.edit_date : info.object.date);
    if (userLocation != null) {
        float distance = location.distanceTo(userLocation);
        if (distance < 1000) {
            distanceTextView.setText(String.format("%s - %d %s", time, (int) (distance), LocaleController.getString("MetersAway", R.string.MetersAway)));
        } else {
            distanceTextView.setText(String.format("%s - %.2f %s", time, distance / 1000.0f, LocaleController.getString("KMetersAway", R.string.KMetersAway)));
        }
    } else {
        distanceTextView.setText(time);
    }

    avatarImageView.setImage(photo, null, avatarDrawable);
}