Skip to content

Instantly share code, notes, and snippets.

View MostafaGad1911's full-sized avatar
💭
Android Developer @SystemsEgypt

Mostafa Gad MostafaGad1911

💭
Android Developer @SystemsEgypt
View GitHub Profile
@MostafaGad1911
MostafaGad1911 / ReversFunction.kt
Last active April 3, 2024 11:22
Reverse Function
private fun reverseArr(array:ArrayList<Int>):ArrayList<Int>{
val reversedArr:ArrayList<Int> = ArrayList()
reversedArr.addAll(array)
var initElementIdx = reversedArr.size
array.forEachIndexed { index, num ->
reversedArr[initElementIdx - 1] = num
initElementIdx -= 1
}
return reversedArr
}
package gad.samples.periodicworkmanager
import android.content.Context
import android.os.Bundle
import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequest
import androidx.work.PeriodicWorkRequestBuilder
object CalendarHelper {
const val ORGANIZER = "My App"
// Projection array. Creating indices for this array instead of doing
// dynamic lookups improves performance.
private val EVENT_PROJECTION: Array<String> = arrayOf(
Events.ORIGINAL_ID, // 0
Events.TITLE, // 1
Events.ALLOWED_REMINDERS, // 2
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/secondaryProgress">
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
<com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutStyle"
android:id="@+id/textInputLyt"
android:layout_width="match_parent"
android:layout_height="60dp"
android:elevation="2dp"
android:textColorHint="@color/color_b9b9b9"
android:textSize="@dimen/dimen_14f"
app:boxCornerRadiusBottomEnd="8dp"
app:boxCornerRadiusBottomStart="8dp"
@MostafaGad1911
MostafaGad1911 / PagingDataToList.kt
Created May 5, 2023 21:07
Convert Paged Data To List
package mostafazsc.projects.exts
import androidx.paging.PagingData
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.single
@Suppress("UNCHECKED_CAST")
suspend fun <T : Any> PagingData<T>.toList(): List<T> {
val flow = PagingData::class.java.getDeclaredField("flow").apply {
isAccessible = true
@MostafaGad1911
MostafaGad1911 / DataStorePreferencesHelper
Created December 10, 2022 22:16
DataStorePreferencesHelper
// implmentation
implementation "androidx.datastore:datastore-preferences:1.0.0-alpha01"
implementation "androidx.datastore:datastore-core:1.0.0-alpha01"
class DataStorePreferencesHelper constructor(context: Context) : DateStoreHelper {
private val applicationContext = context.applicationContext
private val dataStore: DataStore<Preferences>
val log_dump =
"name=Dan B, username=db, email=db@gmail.com, id=123; name=Hannah, username=hsmith, id=333, email=hsm@test.com; name=Dan Brick, username=db, email=db@gmail.com, id=663;"
val toTypedArray = log_dump.split(";").toTypedArray().filter { it.isNotEmpty() }
val filtered:ArrayList<String> = ArrayList()
for (item in toTypedArray) {
item.replace("${item.substringBefore(", id=").substringBefore(",")}", "")
Log.i("GadTest1", "$item")
}
toTypedArray?.forEachIndexed { index, data ->
if (index > 0){
@MostafaGad1911
MostafaGad1911 / LocationExt
Last active November 11, 2021 09:16
Current location Observer
import android.annotation.SuppressLint
import android.app.Activity
import android.location.Location
import android.os.Looper
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationResult