forked from melod1n/fast-messenger
api refactored and cleaned
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.meloda.fast.api.network
|
||||
|
||||
import android.util.Log
|
||||
import com.meloda.fast.api.VKException
|
||||
import okhttp3.Request
|
||||
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>>
|
||||
) : Callback<T> {
|
||||
|
||||
// TODO: 8/31/2021 parse VK errors
|
||||
override fun onResponse(call: Call<T>, response: Response<T>) {
|
||||
val result: Answer<T> = if (response.isSuccessful)
|
||||
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.app.Application
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Handler
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
@@ -37,6 +39,8 @@ class AppGlobal : Application() {
|
||||
companion object {
|
||||
|
||||
lateinit var inputMethodManager: InputMethodManager
|
||||
lateinit var connectivityManager: ConnectivityManager
|
||||
lateinit var clipboardManager: ClipboardManager
|
||||
|
||||
lateinit var preferences: SharedPreferences
|
||||
lateinit var locale: Locale
|
||||
@@ -84,10 +88,13 @@ class AppGlobal : Application() {
|
||||
Companion.packageName = packageName
|
||||
Companion.packageManager = packageManager
|
||||
|
||||
|
||||
screenWidth = AndroidUtils.getDisplayWidth()
|
||||
screenHeight = AndroidUtils.getDisplayHeight()
|
||||
|
||||
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.JSONObject
|
||||
|
||||
// TODO: 8/31/2021 rewrite
|
||||
// TODO: 8/31/2021 rewrite, use job
|
||||
@Deprecated("Absolutely obsolete")
|
||||
class LongPollService : Service() {
|
||||
private var thread: Thread? = null
|
||||
@@ -19,7 +19,6 @@ class LongPollService : Service() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
running = false
|
||||
|
||||
// thread = LowThread(Updater())
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package com.meloda.fast.util
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import android.net.NetworkCapabilities
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.TypedValue
|
||||
import androidx.annotation.AttrRes
|
||||
import com.meloda.fast.BuildConfig
|
||||
import com.meloda.fast.common.AppGlobal
|
||||
|
||||
|
||||
@@ -36,20 +33,18 @@ object AndroidUtils {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
fun hasConnection(): Boolean {
|
||||
return false
|
||||
// val network = AppGlobal.connectivityManager.activeNetwork ?: return false
|
||||
// val activeNetwork =
|
||||
// AppGlobal.connectivityManager.getNetworkCapabilities(network) ?: return false
|
||||
//
|
||||
// return when {
|
||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
|
||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
|
||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
|
||||
// activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) -> true
|
||||
// else -> false
|
||||
// }
|
||||
val network = AppGlobal.connectivityManager.activeNetwork ?: return false
|
||||
val activeNetwork =
|
||||
AppGlobal.connectivityManager.getNetworkCapabilities(network) ?: return false
|
||||
|
||||
return when {
|
||||
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
|
||||
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
|
||||
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
|
||||
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun getDisplayWidth(): Int {
|
||||
@@ -60,37 +55,8 @@ object AndroidUtils {
|
||||
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) {
|
||||
// AppGlobal.clipboardManager.setPrimaryClip(ClipData.newPlainText(label, text))
|
||||
AppGlobal.clipboardManager.setPrimaryClip(ClipData.newPlainText(label, text))
|
||||
}
|
||||
|
||||
fun getThemeAttrColor(context: Context, @AttrRes resId: Int): Int {
|
||||
|
||||
Reference in New Issue
Block a user