Skip to content

Instantly share code, notes, and snippets.

View SeongUgJung's full-sized avatar

Steve SeongUg Jung SeongUgJung

View GitHub Profile
public class MyApplication extends Application {
@Override
public void onCreate() {
// problem point
Realm.init(this);
}
}
public static void init(Context context) {
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : activityManager.getRunningAppProcesses()) {
if (Process.myPid() == processInfo.pid) {
if (TextUtils.equals(processInfo.processName, BuildConfig.APPLICATION_ID)) {
// initiate olny on default process of app
Realm.init(context);
Realm.setDefaultConfiguration(realmConfiguration());
}
// delete realm of default config
Realm.deleteRealm(new RealmConfiguration.Builder().build());
public class DataRepository extends RealmRepository {
private static DataRepository instance;
synchronized public static DataRepository getInstance() {
if (instance == null) {
instance = new BotRepository();
}
return instance;
}
@SeongUgJung
SeongUgJung / app-build.gradle
Last active March 3, 2017 07:54
add dependencies for rxjava
apply plugin: 'me.tatarka.retrolambda'
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependnecies {
@SeongUgJung
SeongUgJung / modified.kt
Created April 27, 2017 12:34
java to kotlin
package com.pluu.support.tstore
import android.content.Context
import com.pluu.support.impl.AbstractWeekApi
import com.pluu.support.impl.NAV_ITEM
import com.pluu.support.impl.NetworkSupportApi
import com.pluu.webtoon.item.Status
import com.pluu.webtoon.item.WebToonInfo
import org.jsoup.Jsoup
import java.util.*
@SeongUgJung
SeongUgJung / LifecycleUtil.kt
Last active July 16, 2017 10:03
Rxjava with Lifecycle-awareness for Lifecycle of Android Architecture Component
object FlowableForLifecycle {
fun <T> flowableForLifecycle(lifecycleOwner: LifecycleOwner, data: Flowable<T>, atLeast:Lifecycle.State = Lifecycle.State.RESUMED): Flowable<T> {
return Flowable.combineLatest(Flowable.create<Lifecycle.State>({ e ->
val observer: GenericLifecycleObserver = object : GenericLifecycleObserver {
override fun getReceiver(): Any = lifecycleOwner
override fun onStateChanged(owner: LifecycleOwner, event: Lifecycle.Event) {
e.takeIf { !e.isCancelled }?.onNext(owner.lifecycle.currentState)
if (event == Lifecycle.Event.ON_DESTROY) {
lifecycleOwner.lifecycle.removeObserver(this)
@SeongUgJung
SeongUgJung / mvvm_raw.kt
Last active January 15, 2020 16:57
mvvm raw
class MainActivity : Activity() {
fun onCreate() {
val tv : TextView = findViewById(R.id.tv)
// ViewModel 정의
val viewModel = MainViewModel()
// ViewModel 옵저빙 후 갱신
viewModel.name.observe {
tv.text = it
}
@SeongUgJung
SeongUgJung / databinding.xml
Last active August 22, 2018 03:12
mvvm databinding
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 데이터바인딩 정의 -->
<data>
<variable
name="vm"
type="MainViewModel" />
</data>
@SeongUgJung
SeongUgJung / ItemAdapter.kt
Created August 22, 2018 15:46
recycler adapter and data
class ItemAdapter : RecyclerView.Adapter() {
var items : List<Item> = emptyList()
}