This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //save object as json | |
| val adapter = Moshi.Builder().build().adapter(SavedObject::class.java) | |
| val json = adapter.toJson(it.data?.body()?.result) | |
| prefManager.saveString("Saved Object", json) | |
| //load object | |
| val objectJson = prefManager.getString("Saved Object") | |
| val adapter = Moshi.Builder().build().adapter(SavedObject::class.java) | |
| val result = adapter.fromJson(objectJson) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This sample count down timer | |
| * for auction app when bid start and end | |
| */ | |
| private lateinit var countDownTimer: CountDownTimer | |
| private var difference = 0L | |
| private var isStart = false | |
| private var startTime = "" // you can chage it with Date | |
| private var endTime = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RepoTest(private val testDao:TestDao){ //inject dao using Koin | |
| fun insertTest(test:Test) : Single<Resource<String>> = testDao.insertTest(test) | |
| . .subscribeOn(Schedulers.io()) | |
| .map<Resource<String>> { t -> Resource.Success(t.toString()) } // convert primary key value to String | |
| .onErrorReturn { Resource.Failure(it) } | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class NetworkBoundResource<ResultType, RequestType> { | |
| private lateinit var result: Flowable<Resource<ResultType>> | |
| init { | |
| // Lazy disk observable. | |
| val diskObservable = Flowable.defer { | |
| loadFromDb() | |
| // Read from disk on Computation Scheduler | |
| .subscribeOn(Schedulers.computation()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end | |
| import android.support.v7.widget.RecyclerView | |
| import android.view.LayoutInflater | |
| import android.view.View | |
| import android.view.ViewGroup | |
| import java.util.* | |
| #parse("File Header.java") | |
| class ${NAME} (private val dataList:List<${Model_Class}>): RecyclerView.Adapter<${NAME}.${ViewHolder_Class}>() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CounterActivity extends AppCompatActivity { | |
| private int nilaiSkor = 0; | |
| private TextView tvCounter; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_counter); // layout counter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun generateTextInputLayout(count: Int) { | |
| ll_root.removeAllViews() // remove prevous TextInputEditText on root layout | |
| for (item in 1..count) { | |
| //create textInputLayout | |
| val textInputLayout = TextInputLayout(this) | |
| ll_root.addView(textInputLayout) // add View TextInputLayout in LinearLayout | |
| //create textInputEditText | |
| val textInputEditText = TextInputEditText(this) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface ClickListener { | |
| void onClick(View view, int position); | |
| void onLongClick(View view, int position); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:id="@+id/layout_order_progress_status" | |
| android:layout_width="wrap_content" | |
| android:layout_height="fill_parent" | |
| android:layout_weight="1.0" | |
| tools:ignore="all"> | |
| <TextView |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | |
| @Override | |
| public void onScrollStateChanged(RecyclerView recyclerView, int newState) { | |
| if (newState == RecyclerView.SCROLL_STATE_IDLE) { | |
| LinearLayoutManager layout = (LinearLayoutManager) recyclerView.getLayoutManager(); | |
| int currentPosition = layout.findFirstVisibleItemPosition() - 1; | |
| try { | |
| Logger.d("currentPosition : " + currentPosition + "temp : " + previousPosition); | |
| if (responseItemList.get(currentPosition).getFile().get(0).getAttachment_type().toLowerCase() |