Skip to content

Commit

Permalink
6
Browse files Browse the repository at this point in the history
6
  • Loading branch information
umerov1999 committed Jan 10, 2023
1 parent ba34565 commit 9ca39ff
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 142 deletions.
3 changes: 2 additions & 1 deletion app_fenrir/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
android:allowAudioPlaybackCapture="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -66,7 +67,7 @@
android:supportsRtl="false"
android:theme="@style/App.DayNight"
android:usesCleartextTraffic="true"
tools:targetApi="s">
tools:targetApi="tiramisu">

<meta-data
android:name="com.google.android.gms.version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class KeyExchangeService : Service() {
}
mUtilsInteractor.getServerTime(accountId)
.fromIOToMain()
.delay(1500, TimeUnit.MILLISECONDS)
.subscribe({
val session = KeyExchangeSession.createOutSession(
it, accountId, peerId, keyLocationPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface IRequestsView : IMvpView, IErrorView {
fun showUserWall(accountId: Int, user: User)
fun showRefreshing(refreshing: Boolean)
fun showNotRequests(data: List<Owner>, accountId: Int, ownerId: Int)
fun updateCount(count: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.inputmethod.InputMethodManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.textview.MaterialTextView
import dev.ragnarok.fenrir.Constants
import dev.ragnarok.fenrir.Extra
import dev.ragnarok.fenrir.R
Expand All @@ -31,14 +32,16 @@ class RequestsFragment : BaseMvpFragment<RequestsPresenter, IRequestsView>(),
FriendsRecycleAdapter.Listener, IRequestsView {
private var mAdapter: FriendsRecycleAdapter? = null
private var mSwipeRefreshLayout: SwipeRefreshLayout? = null
private var mCount: MaterialTextView? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
val root = inflater.inflate(R.layout.fragment_friends, container, false)
val root = inflater.inflate(R.layout.fragment_requests, container, false)
val mRecyclerView: RecyclerView = root.findViewById(R.id.list)
mCount = root.findViewById(R.id.count_data)
mSwipeRefreshLayout = root.findViewById(R.id.refresh)
mSwipeRefreshLayout?.setOnRefreshListener {
presenter?.fireRefresh()
Expand Down Expand Up @@ -79,6 +82,15 @@ class RequestsFragment : BaseMvpFragment<RequestsPresenter, IRequestsView>(),
return root
}

override fun updateCount(count: Int) {
if (count <= 0) {
mCount?.visibility = View.GONE
} else {
mCount?.visibility = View.VISIBLE
}
mCount?.text = getString(R.string.people_count, count)
}

override fun getPresenterFactory(saveInstanceState: Bundle?): IPresenterFactory<RequestsPresenter> {
return object : IPresenterFactory<RequestsPresenter> {
override fun create(): RequestsPresenter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class RequestsPresenter(accountId: Int, private val userId: Int, savedInstanceSt
override fun onGuiCreated(viewHost: IRequestsView) {
super.onGuiCreated(viewHost)
viewHost.displayData(data, isSearchNow)
viewHost.updateCount(allData.size)
resolveSwipeRefreshAvailability()
}

Expand Down Expand Up @@ -129,6 +130,7 @@ class RequestsPresenter(accountId: Int, private val userId: Int, savedInstanceSt
}
offset += if (isNotFriendShow) 1000 else 200
resolveRefreshingView()
view?.updateCount(allData.size)
}

private fun loadAllCachedData() {
Expand Down Expand Up @@ -335,7 +337,6 @@ class RequestsPresenter(accountId: Int, private val userId: Int, savedInstanceSt
private const val SEARCH_CACHE = 1
private const val SEARCH_WEB = 2
private const val WEB_SEARCH_DELAY = 1000
private const val WEB_SEARCH_COUNT_PER_LOAD = 100
internal fun allow(user: User, preparedQ: String): Boolean {
val full = user.fullName.lowercase(Locale.getDefault())
return full.contains(preparedQ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,69 @@ import android.os.Build
object ImageHelper {
fun getRoundedBitmap(workBitmap: Bitmap?): Bitmap? {
workBitmap ?: return null
var bitmap = workBitmap
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && bitmap.config == Bitmap.Config.HARDWARE) {
val tmpBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true)
bitmap.recycle()
bitmap = tmpBitmap
if (bitmap == null) {
return null
}
val bitmapWidth = workBitmap.width
val bitmapHeight = workBitmap.height
val isHardware =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && workBitmap.config == Bitmap.Config.HARDWARE

var output: Bitmap? = null
val canvas: Canvas
var obj: Picture? = null
if (isHardware) {
obj = Picture()
canvas = obj.beginRecording(bitmapWidth, bitmapHeight)
} else {
output = Bitmap.createBitmap(bitmapWidth, bitmapHeight, workBitmap.config)
canvas = Canvas(output)
}
val output = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(output)
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)
val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
paint.shader = BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
canvas.drawOval(0f, 0f, bitmap.width.toFloat(), bitmap.height.toFloat(), paint)
if (bitmap != output) {
bitmap.recycle()
paint.shader = BitmapShader(workBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
canvas.drawOval(0f, 0f, bitmapWidth.toFloat(), bitmapHeight.toFloat(), paint)
workBitmap.recycle()
if (isHardware && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
obj?.endRecording()
output =
obj?.let { Bitmap.createBitmap(it, it.width, it.height, Bitmap.Config.HARDWARE) }
}
return output
}

fun getEllipseBitmap(workBitmap: Bitmap?, angle: Float): Bitmap? {
workBitmap ?: return null
var bitmap = workBitmap
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && bitmap.config == Bitmap.Config.HARDWARE) {
val tmpBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true)
bitmap.recycle()
bitmap = tmpBitmap
if (bitmap == null) {
return null
}
val bitmapWidth = workBitmap.width
val bitmapHeight = workBitmap.height
val isHardware =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && workBitmap.config == Bitmap.Config.HARDWARE

var output: Bitmap? = null
val canvas: Canvas
var obj: Picture? = null
if (isHardware) {
obj = Picture()
canvas = obj.beginRecording(bitmapWidth, bitmapHeight)
} else {
output = Bitmap.createBitmap(bitmapWidth, bitmapHeight, workBitmap.config)
canvas = Canvas(output)
}
val output = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(output)
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)
val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
paint.shader = BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
val pth = (bitmap.width + bitmap.height).toFloat() / 2
paint.shader = BitmapShader(workBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
val pth = (bitmapWidth + bitmapHeight).toFloat() / 2
canvas.drawRoundRect(
0f,
0f,
bitmap.width.toFloat(),
bitmap.height.toFloat(),
bitmapWidth.toFloat(),
bitmapHeight.toFloat(),
pth * angle,
pth * angle,
paint
)
if (bitmap != output) {
bitmap.recycle()
workBitmap.recycle()
if (isHardware && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
obj?.endRecording()
output =
obj?.let { Bitmap.createBitmap(it, it.width, it.height, Bitmap.Config.HARDWARE) }
}
return output
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,37 @@ class MonochromeTransformation : Transformation {
}

fun transform(source: Bitmap): Bitmap? {
var bitmap = source
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && bitmap.config == Bitmap.Config.HARDWARE) {
val tmpBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true)
bitmap.recycle()
bitmap = tmpBitmap
if (bitmap == null) {
return null
}
val bitmapWidth = source.width
val bitmapHeight = source.height
val isHardware =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && source.config == Bitmap.Config.HARDWARE

var output: Bitmap? = null
val canvas: Canvas
var obj: Picture? = null
if (isHardware) {
obj = Picture()
canvas = obj.beginRecording(bitmapWidth, bitmapHeight)
} else {
output = Bitmap.createBitmap(bitmapWidth, bitmapHeight, source.config)
canvas = Canvas(output)
}
val matrix = ColorMatrix()
matrix.setSaturation(0f)

val bitmapCopy = Bitmap.createBitmap(
bitmap.width,
bitmap.height, Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmapCopy)
val paint = Paint()
val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
val colorFilter = ColorMatrixColorFilter(matrix)
paint.colorFilter = colorFilter
canvas.drawBitmap(bitmap, 0f, 0f, paint)
bitmap.recycle()
return bitmapCopy
paint.shader = BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)

canvas.drawRect(0f, 0f, bitmapWidth.toFloat(), bitmapHeight.toFloat(), paint)
source.recycle()
if (isHardware && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
obj?.endRecording()
output =
obj?.let { Bitmap.createBitmap(it, it.width, it.height, Bitmap.Config.HARDWARE) }
}
return output
}

override fun localTransform(source: Bitmap?): Bitmap? {
Expand Down
Loading

0 comments on commit 9ca39ff

Please sign in to comment.