rename constants and addGrayPhoto
This commit is contained in:
parent
6bfece0744
commit
8815e8968b
3 changed files with 19 additions and 19 deletions
|
@ -323,7 +323,7 @@ class TelegramHelper private constructor() {
|
||||||
|
|
||||||
fun getUserGreyPhotoPath(user: TdApi.User): String? {
|
fun getUserGreyPhotoPath(user: TdApi.User): String? {
|
||||||
return if (hasGrayscaleUserPhoto(user.id)) {
|
return if (hasGrayscaleUserPhoto(user.id)) {
|
||||||
"$appDir/$PROFILE_GRAYSCALE_PHOTOS_DIR${user.id}$SAVED_GRAYSCALE_PHOTOS_EXT"
|
"$appDir/$GRAYSCALE_PHOTOS_DIR${user.id}$GRAYSCALE_PHOTOS_EXT"
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasGrayscaleUserPhoto(userId: Int): Boolean {
|
fun hasGrayscaleUserPhoto(userId: Int): Boolean {
|
||||||
return File("$appDir/$PROFILE_GRAYSCALE_PHOTOS_DIR$userId$SAVED_GRAYSCALE_PHOTOS_EXT").exists()
|
return File("$appDir/$GRAYSCALE_PHOTOS_DIR$userId$GRAYSCALE_PHOTOS_EXT").exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasLocalUserPhoto(user: TdApi.User): Boolean {
|
private fun hasLocalUserPhoto(user: TdApi.User): Boolean {
|
||||||
|
|
|
@ -25,8 +25,8 @@ import net.osmand.telegram.ui.LoginDialogFragment.LoginDialogType
|
||||||
import net.osmand.telegram.ui.MyLocationTabFragment.ActionButtonsListener
|
import net.osmand.telegram.ui.MyLocationTabFragment.ActionButtonsListener
|
||||||
import net.osmand.telegram.ui.views.LockableViewPager
|
import net.osmand.telegram.ui.views.LockableViewPager
|
||||||
import net.osmand.telegram.utils.AndroidUtils
|
import net.osmand.telegram.utils.AndroidUtils
|
||||||
import net.osmand.telegram.utils.PROFILE_GRAYSCALE_PHOTOS_DIR
|
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_DIR
|
||||||
import net.osmand.telegram.utils.SAVED_GRAYSCALE_PHOTOS_EXT
|
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_EXT
|
||||||
import org.drinkless.td.libcore.telegram.TdApi
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
|
|
||||||
override fun onTelegramChatsChanged() {
|
override fun onTelegramChatsChanged() {
|
||||||
telegramHelper.getMessagesByChatIds(settings.locHistoryTime).forEach {
|
telegramHelper.getMessagesByChatIds(settings.locHistoryTime).forEach {
|
||||||
checkUserPhotoFromChat(it.key)
|
addGrayPhoto(it.key)
|
||||||
}
|
}
|
||||||
runOnUi {
|
runOnUi {
|
||||||
listeners.forEach { it.get()?.onTelegramChatsChanged() }
|
listeners.forEach { it.get()?.onTelegramChatsChanged() }
|
||||||
|
@ -232,7 +232,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTelegramChatChanged(chat: TdApi.Chat) {
|
override fun onTelegramChatChanged(chat: TdApi.Chat) {
|
||||||
checkUserPhotoFromChat(chat.id)
|
addGrayPhoto(chat.id)
|
||||||
runOnUi {
|
runOnUi {
|
||||||
listeners.forEach { it.get()?.onTelegramChatChanged(chat) }
|
listeners.forEach { it.get()?.onTelegramChatChanged(chat) }
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
override fun onTelegramUserChanged(user: TdApi.User) {
|
override fun onTelegramUserChanged(user: TdApi.User) {
|
||||||
val photoPath = telegramHelper.getUserPhotoPath(user)
|
val photoPath = telegramHelper.getUserPhotoPath(user)
|
||||||
if (photoPath != null) {
|
if (photoPath != null) {
|
||||||
checkUserGrayPhoto(user.id, photoPath)
|
addGrayPhoto(user.id, photoPath)
|
||||||
}
|
}
|
||||||
val message = telegramHelper.getUserMessage(user)
|
val message = telegramHelper.getUserMessage(user)
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
|
@ -268,7 +268,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) {
|
override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) {
|
||||||
checkUserPhotoFromChat(chatId)
|
addGrayPhoto(chatId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>) {}
|
override fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>) {}
|
||||||
|
@ -351,19 +351,19 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkUserPhotoFromChat(chatId: Long) {
|
private fun addGrayPhoto(chatId: Long) {
|
||||||
val chat = app.telegramHelper.getChat(chatId)
|
val chat = app.telegramHelper.getChat(chatId)
|
||||||
val chatIconPath = chat?.photo?.small?.local?.path
|
val chatIconPath = chat?.photo?.small?.local?.path
|
||||||
if (chat != null && chatIconPath != null) {
|
if (chat != null && chatIconPath != null) {
|
||||||
checkUserGrayPhoto(app.telegramHelper.getUserIdFromChatType(chat.type), chatIconPath)
|
addGrayPhoto(app.telegramHelper.getUserIdFromChatType(chat.type), chatIconPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkUserGrayPhoto(userId: Int, userOriginalPhotoPath: String) {
|
private fun addGrayPhoto(userId: Int, originalPhotoPath: String) {
|
||||||
if (userId != 0 && !app.telegramHelper.hasGrayscaleUserPhoto(userId)) {
|
if (userId != 0 && !app.telegramHelper.hasGrayscaleUserPhoto(userId)) {
|
||||||
app.uiUtils.convertAndSaveUserGrayPhoto(
|
app.uiUtils.convertAndSaveGrayPhoto(
|
||||||
userOriginalPhotoPath,
|
originalPhotoPath,
|
||||||
"${app.filesDir.absolutePath}/$PROFILE_GRAYSCALE_PHOTOS_DIR$userId$SAVED_GRAYSCALE_PHOTOS_EXT"
|
"${app.filesDir.absolutePath}/$GRAYSCALE_PHOTOS_DIR$userId$GRAYSCALE_PHOTOS_EXT"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,9 @@ import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
const val PROFILE_GRAYSCALE_PHOTOS_DIR = "profile_grayscale_photos/"
|
const val GRAYSCALE_PHOTOS_DIR = "grayscale_photos/"
|
||||||
|
|
||||||
const val SAVED_GRAYSCALE_PHOTOS_EXT = ".jpeg"
|
const val GRAYSCALE_PHOTOS_EXT = ".jpeg"
|
||||||
|
|
||||||
class UiUtils(private val app: TelegramApplication) {
|
class UiUtils(private val app: TelegramApplication) {
|
||||||
private val drawableCache = LinkedHashMap<Long, Drawable>()
|
private val drawableCache = LinkedHashMap<Long, Drawable>()
|
||||||
|
@ -115,11 +115,11 @@ class UiUtils(private val app: TelegramApplication) {
|
||||||
return getDrawable(id, if (light) R.color.icon_light else 0)
|
return getDrawable(id, if (light) R.color.icon_light else 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertAndSaveUserGrayPhoto(userOriginalPhotoPath: String, greyPhotoPath: String) {
|
fun convertAndSaveGrayPhoto(originalPhotoPath: String, greyPhotoPath: String) {
|
||||||
if (File(userOriginalPhotoPath).exists()) {
|
if (File(originalPhotoPath).exists()) {
|
||||||
ConvertPhotoToGrayscale().executeOnExecutor(
|
ConvertPhotoToGrayscale().executeOnExecutor(
|
||||||
AsyncTask.THREAD_POOL_EXECUTOR,
|
AsyncTask.THREAD_POOL_EXECUTOR,
|
||||||
userOriginalPhotoPath,
|
originalPhotoPath,
|
||||||
greyPhotoPath
|
greyPhotoPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue