Skip to content

Instantly share code, notes, and snippets.

View DHosseiny's full-sized avatar
🏠
Working from home

Seyyed davud hosseiny DHosseiny

🏠
Working from home
View GitHub Profile
@DHosseiny
DHosseiny / build.gradle
Last active May 18, 2023 10:56
Periodically migrate multi-module app from dagger to hilt
implementation "com.google.dagger:hilt-android:$hilt-latest-version"
kapt "com.google.dagger:hilt-android-compiler:$hilt-latest-version"
@DHosseiny
DHosseiny / DataStoreExts.kt
Last active November 9, 2021 07:57
DataStore Delegation
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@DHosseiny
DHosseiny / MainActivity.kt
Created June 22, 2020 09:32
Adding a view to UI from Background Thread
import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.os.Message
import android.view.WindowManager
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
@DHosseiny
DHosseiny / DeleteBuildFolders.bat
Last active June 8, 2020 11:25
Runnable Kotlin Script example with windows batch(double click .bat file to run) -- This example Searches all neighbor folders for android projects and deletes project and it's modules "build" folders(For reducing disk size). *need one time set "kotlinc" enviroment variable(See comments for guidance).
%kotlinc% -script DeleteBuildFolders.kts -- -dir .
:: "." is default path you can change it to any folder you want to work on that folder ^
:: (script workes on current folder without "-dir" argument)"
:: "^" can be used for multiline commands
@DHosseiny
DHosseiny / Theme.kt
Created March 28, 2020 11:16
Theme Switcher Code snippets
class Theme : BaseObservable() {
@Bindable val colorPrimary: String = "colorPrimary"
@Bindable val colorPrimaryDark: String = "colorPrimaryDark"
...
}
@DHosseiny
DHosseiny / BasePreferencesDataSource.kt
Created February 23, 2020 12:43
Delegates for SharedPreferences(Copy paste usage) (Maybe add some other delegates for other types soon)
import android.content.SharedPreferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
abstract class BasePreferencesDataSource {
protected abstract val preferences : SharedPreferences
protected class StringPrefProperty(private val key: String) : ReadWriteProperty<BasePreferencesDataSource, String> {
@DHosseiny
DHosseiny / FileUtils.java
Last active January 9, 2020 12:12
Open any type of file
public class FileUtils {
/**
* @return The MIME type for the given file.
*/
public static String getMimeType(File file) {
String extension = getExtension(file.getName()).toLowerCase();
if (!TextUtils.isEmpty(extension) && extension.length() > 1)
class PreferenceRepositoryTest {
@get:Rule
var instantExecutorRule = InstantTaskExecutorRule()
@Mock
private lateinit var connectionApiServices: ConnectionApiServices
private lateinit var preferenceRepository: PrefrenceRepository
@DHosseiny
DHosseiny / DaoExtentions.kt
Last active December 3, 2018 23:57
Kotlin Extension Functions + Entity Dao
import com.example.db.ConversationDao.Properties.Mid
import com.example.db.UserDao.Properties.Username
fun UserDao.getByUsername(username: String): User =
queryBuilder().where(Username.eq(username)).unique()
fun MessageDao.getMessage(mid: Long): Message =
queryBuilder().where(Mid.eq(mid)).unique()
@DHosseiny
DHosseiny / DaoExtentions.kt
Created November 8, 2018 11:00
Kotlin Extention Functions + Entity Dao
package com.izigzag.messenger.model.db
import com.izigzag.messenger.model.db.ConversationDao.Properties.Mid
import com.izigzag.messenger.model.db.UserDao.Properties.Username
fun UserDao.getByUsername(username: String): User =
queryBuilder().where(Username.eq(username)).unique()
fun MessageDao.getMessage(mid: Long): Message =
queryBuilder().where(Mid.eq(mid)).unique()