Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Usually respond within a day

Bao Phan dphans

🚀
Usually respond within a day
View GitHub Profile
@dphans
dphans / gist:4c265667abd3c23a124cf9142fa4bc73
Last active Sep 2, 2021
Determine if iOS app is running on a Mac, or other devices (iPad, iPhone, iWatch) programmatically
View gist:4c265667abd3c23a124cf9142fa4bc73
/// Swift version: 4
/// Last updated: Jul 21, 2020
// define somewhere... (utilities, constants,...)
enum TargetDevice {
case nativeMac
case iPad
case iPhone
case iWatch
View DetectingNightMode.kt
val isNightMode = this@BaseActivity.resources.configuration.uiMode
.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
@dphans
dphans / DetectingNightMode.kt
Last active Sep 22, 2019
Detecting deivces night mode programmatically
View DetectingNightMode.kt
// check device state is in dark mode
val isDarkMode = this@BaseActivity.resources.configuration.uiMode
.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
// retrieve current themes background color
val typedValue = TypedValue()
this@BaseActivity.theme.resolveAttribute(android.R.attr.colorBackground, typedValue, true)
// allow activity can update system system bars
this@BaseActivity.window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
View keybase.md

Keybase proof

I hereby claim:

  • I am dphans on github.
  • I am dphans (https://keybase.io/dphans) on keybase.
  • I have a public key ASDEy5TidGRxHLeBpHFnS5D8Sk5SSsp4GEHBdDSjDoLOlgo

To claim this, I am signing this object:

View MainActivity.kt
package com.dinophan.authapp.ui.activities
import android.view.View
import com.dinophan.authapp.R
import com.dinophan.authapp.bases.BaseActivity
import com.dinophan.authapp.databinding.ActivityMainBinding
import com.dinophan.authapp.models.UserModel
import com.dinophan.authapp.modules.mock.APIMock
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>
<variable name="isFormValidated" type="Boolean" />
<variable name="isFormSubmitting" type="Boolean" />
<variable name="isRegisterationState" type="Boolean" />
<variable name="formErrorMessage" type="String" />
<variable name="presenter" type="com.dinophan.authapp.ui.activities.MainActivity.Presenter" />
</data>
View MainActivity.kt
package com.dinophan.authapp.ui.activities
import android.view.View
import com.dinophan.authapp.R
import com.dinophan.authapp.bases.BaseActivity
import com.dinophan.authapp.databinding.ActivityMainBinding
import com.dinophan.authapp.models.UserModel
import com.dinophan.authapp.modules.mock.APIMock
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
View UserModel.kt
package com.dinophan.authapp.models
import com.dinophan.authapp.bases.BaseModel
class UserModel: BaseModel() {
var username: String = String()
var password: String = String()
override fun validates(): Boolean {
View BaseModel.kt
package com.dinophan.authapp.bases
import com.google.gson.Gson
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
import java.io.Serializable
@Suppress("MemberVisibilityCanBePrivate", "RedundantVisibilityModifier")
abstract class BaseModel: Serializable {
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">