forked from melod1n/fast-messenger
api refactored and cleaned
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package com.meloda.fast.api.network
|
package com.meloda.fast.api.network
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import com.meloda.fast.api.VKException
|
import com.meloda.fast.api.VKException
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
@@ -76,7 +75,6 @@ internal class ResultCall<T>(proxy: Call<T>) : CallDelegate<T, Answer<T>>(proxy)
|
|||||||
private val callback: Callback<Answer<T>>
|
private val callback: Callback<Answer<T>>
|
||||||
) : Callback<T> {
|
) : Callback<T> {
|
||||||
|
|
||||||
// TODO: 8/31/2021 parse VK errors
|
|
||||||
override fun onResponse(call: Call<T>, response: Response<T>) {
|
override fun onResponse(call: Call<T>, response: Response<T>) {
|
||||||
val result: Answer<T> = if (response.isSuccessful)
|
val result: Answer<T> = if (response.isSuccessful)
|
||||||
Answer.Success(response.body() as T)
|
Answer.Success(response.body() as T)
|
||||||
|
|||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
package com.meloda.fast.api.network.request
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
class RequestMessagesGetConversations(
|
|
||||||
@SerializedName("offset")
|
|
||||||
private val offset: Int = 0,
|
|
||||||
|
|
||||||
@SerializedName("count")
|
|
||||||
private val count: Int = 0,
|
|
||||||
|
|
||||||
//values = all, unread
|
|
||||||
@SerializedName("filter")
|
|
||||||
private val filter: String = "",
|
|
||||||
|
|
||||||
@SerializedName("extended")
|
|
||||||
private val extended: Boolean = false,
|
|
||||||
|
|
||||||
@SerializedName("fields")
|
|
||||||
private var fields: String = ""
|
|
||||||
)
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package com.meloda.fast.api.network.response
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.meloda.fast.api.network.response
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
|
|
||||||
class MessagesResponse(
|
|
||||||
val count: Int
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Parcelize
|
|
||||||
data class GetConversationsResponse(val a: String) : Parcelable
|
|
||||||
// TODO: 7/12/2021 use hilt for this like in LIR and make simple conversations' screen
|
|
||||||
@@ -2,11 +2,13 @@ package com.meloda.fast.common
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
|
import android.net.ConnectivityManager
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import androidx.core.content.pm.PackageInfoCompat
|
import androidx.core.content.pm.PackageInfoCompat
|
||||||
@@ -37,6 +39,8 @@ class AppGlobal : Application() {
|
|||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
lateinit var inputMethodManager: InputMethodManager
|
lateinit var inputMethodManager: InputMethodManager
|
||||||
|
lateinit var connectivityManager: ConnectivityManager
|
||||||
|
lateinit var clipboardManager: ClipboardManager
|
||||||
|
|
||||||
lateinit var preferences: SharedPreferences
|
lateinit var preferences: SharedPreferences
|
||||||
lateinit var locale: Locale
|
lateinit var locale: Locale
|
||||||
@@ -84,10 +88,13 @@ class AppGlobal : Application() {
|
|||||||
Companion.packageName = packageName
|
Companion.packageName = packageName
|
||||||
Companion.packageManager = packageManager
|
Companion.packageManager = packageManager
|
||||||
|
|
||||||
|
|
||||||
screenWidth = AndroidUtils.getDisplayWidth()
|
screenWidth = AndroidUtils.getDisplayWidth()
|
||||||
screenHeight = AndroidUtils.getDisplayHeight()
|
screenHeight = AndroidUtils.getDisplayHeight()
|
||||||
|
|
||||||
inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ import com.meloda.fast.util.AndroidUtils
|
|||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
// TODO: 8/31/2021 rewrite
|
// TODO: 8/31/2021 rewrite, use job
|
||||||
@Deprecated("Absolutely obsolete")
|
@Deprecated("Absolutely obsolete")
|
||||||
class LongPollService : Service() {
|
class LongPollService : Service() {
|
||||||
private var thread: Thread? = null
|
private var thread: Thread? = null
|
||||||
@@ -19,7 +19,6 @@ class LongPollService : Service() {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
running = false
|
running = false
|
||||||
|
|
||||||
// thread = LowThread(Updater())
|
// thread = LowThread(Updater())
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
package com.meloda.fast.util
|
package com.meloda.fast.util
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
import android.net.NetworkCapabilities
|
||||||
import android.os.Build
|
|
||||||
import android.provider.Settings
|
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import com.meloda.fast.BuildConfig
|
|
||||||
import com.meloda.fast.common.AppGlobal
|
import com.meloda.fast.common.AppGlobal
|
||||||
|
|
||||||
|
|
||||||
@@ -36,20 +33,18 @@ object AndroidUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
|
||||||
fun hasConnection(): Boolean {
|
fun hasConnection(): Boolean {
|
||||||
return false
|
val network = AppGlobal.connectivityManager.activeNetwork ?: return false
|
||||||
// val network = AppGlobal.connectivityManager.activeNetwork ?: return false
|
val activeNetwork =
|
||||||
// val activeNetwork =
|
AppGlobal.connectivityManager.getNetworkCapabilities(network) ?: return false
|
||||||
// AppGlobal.connectivityManager.getNetworkCapabilities(network) ?: return false
|
|
||||||
//
|
return when {
|
||||||
// return when {
|
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
|
||||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
|
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
|
||||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
|
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
|
||||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
|
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) -> true
|
||||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) -> true
|
else -> false
|
||||||
// else -> false
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDisplayWidth(): Int {
|
fun getDisplayWidth(): Int {
|
||||||
@@ -60,37 +55,8 @@ object AndroidUtils {
|
|||||||
return AppGlobal.resources.displayMetrics.heightPixels
|
return AppGlobal.resources.displayMetrics.heightPixels
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isDeveloperSettingsEnabled(context: Context) = Settings.Secure.getInt(
|
|
||||||
context.contentResolver,
|
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
|
|
||||||
0
|
|
||||||
) == 1
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
fun isCanInstallUnknownApps(context: Context) =
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
||||||
Settings.Secure.getInt(
|
|
||||||
context.contentResolver,
|
|
||||||
Settings.Secure.INSTALL_NON_MARKET_APPS
|
|
||||||
) == 1
|
|
||||||
} else {
|
|
||||||
AppGlobal.packageManager.canRequestPackageInstalls()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun openInstallUnknownAppsScreen(context: Context) {
|
|
||||||
context.startActivity(Intent().apply {
|
|
||||||
action = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
||||||
Settings.ACTION_SECURITY_SETTINGS
|
|
||||||
} else {
|
|
||||||
data = Uri.parse("package:${BuildConfig.APPLICATION_ID}")
|
|
||||||
Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
fun copyText(label: String? = "", text: String) {
|
fun copyText(label: String? = "", text: String) {
|
||||||
// AppGlobal.clipboardManager.setPrimaryClip(ClipData.newPlainText(label, text))
|
AppGlobal.clipboardManager.setPrimaryClip(ClipData.newPlainText(label, text))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getThemeAttrColor(context: Context, @AttrRes resId: Int): Int {
|
fun getThemeAttrColor(context: Context, @AttrRes resId: Int): Int {
|
||||||
|
|||||||
Reference in New Issue
Block a user