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 / BaseAdapter.java
Created February 16, 2018 08:12
Databinding BaseAdapter based on george mount's medium post.
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by Davud. MyApplication project.
*/
class MainActivity : AppCompatActivity() {
private val messageView : TextView by lazy {
// runs on first access of messageView
findViewById(R.id.message_view) as TextView
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@DHosseiny
DHosseiny / Optional.kt
Last active November 6, 2018 07:16
Optional for android api lower than 24.
class Optional<T> {
private var value: T? = null
private constructor() {
this.value = null
}
private constructor(value: T) {
this.value = value
@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()
@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()
class PreferenceRepositoryTest {
@get:Rule
var instantExecutorRule = InstantTaskExecutorRule()
@Mock
private lateinit var connectionApiServices: ConnectionApiServices
private lateinit var preferenceRepository: PrefrenceRepository
@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)
@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 / 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 / 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