rename constants and addGrayPhoto

This commit is contained in:
Chumva 2018-08-28 15:26:48 +03:00
parent 6bfece0744
commit 8815e8968b
3 changed files with 19 additions and 19 deletions

View file

@ -323,7 +323,7 @@ class TelegramHelper private constructor() {
fun getUserGreyPhotoPath(user: TdApi.User): String? {
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 {
null
}
@ -368,7 +368,7 @@ class TelegramHelper private constructor() {
}
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 {

View file

@ -25,8 +25,8 @@ import net.osmand.telegram.ui.LoginDialogFragment.LoginDialogType
import net.osmand.telegram.ui.MyLocationTabFragment.ActionButtonsListener
import net.osmand.telegram.ui.views.LockableViewPager
import net.osmand.telegram.utils.AndroidUtils
import net.osmand.telegram.utils.PROFILE_GRAYSCALE_PHOTOS_DIR
import net.osmand.telegram.utils.SAVED_GRAYSCALE_PHOTOS_EXT
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_DIR
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_EXT
import org.drinkless.td.libcore.telegram.TdApi
import java.lang.ref.WeakReference
@ -224,7 +224,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
override fun onTelegramChatsChanged() {
telegramHelper.getMessagesByChatIds(settings.locHistoryTime).forEach {
checkUserPhotoFromChat(it.key)
addGrayPhoto(it.key)
}
runOnUi {
listeners.forEach { it.get()?.onTelegramChatsChanged() }
@ -232,7 +232,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
}
override fun onTelegramChatChanged(chat: TdApi.Chat) {
checkUserPhotoFromChat(chat.id)
addGrayPhoto(chat.id)
runOnUi {
listeners.forEach { it.get()?.onTelegramChatChanged(chat) }
}
@ -241,7 +241,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
override fun onTelegramUserChanged(user: TdApi.User) {
val photoPath = telegramHelper.getUserPhotoPath(user)
if (photoPath != null) {
checkUserGrayPhoto(user.id, photoPath)
addGrayPhoto(user.id, photoPath)
}
val message = telegramHelper.getUserMessage(user)
if (message != null) {
@ -268,7 +268,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
}
override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) {
checkUserPhotoFromChat(chatId)
addGrayPhoto(chatId)
}
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 chatIconPath = chat?.photo?.small?.local?.path
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)) {
app.uiUtils.convertAndSaveUserGrayPhoto(
userOriginalPhotoPath,
"${app.filesDir.absolutePath}/$PROFILE_GRAYSCALE_PHOTOS_DIR$userId$SAVED_GRAYSCALE_PHOTOS_EXT"
app.uiUtils.convertAndSaveGrayPhoto(
originalPhotoPath,
"${app.filesDir.absolutePath}/$GRAYSCALE_PHOTOS_DIR$userId$GRAYSCALE_PHOTOS_EXT"
)
}
}

View file

@ -27,9 +27,9 @@ import java.io.FileOutputStream
import java.io.IOException
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) {
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)
}
fun convertAndSaveUserGrayPhoto(userOriginalPhotoPath: String, greyPhotoPath: String) {
if (File(userOriginalPhotoPath).exists()) {
fun convertAndSaveGrayPhoto(originalPhotoPath: String, greyPhotoPath: String) {
if (File(originalPhotoPath).exists()) {
ConvertPhotoToGrayscale().executeOnExecutor(
AsyncTask.THREAD_POOL_EXECUTOR,
userOriginalPhotoPath,
originalPhotoPath,
greyPhotoPath
)
}