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 LoginFragment extends Fragment{ | |
| @Inject | |
| Context mContext; | |
| @Override | |
| public void onAttach(Context context) { | |
| AndroidSupportInjection.inject(this); | |
| super.onAttach(context); | |
| } |
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
| @Module | |
| public class AppModule { | |
| @Singleton | |
| @Provides | |
| Context provideContext(Application application) { | |
| return application; | |
| } | |
| } |
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 static BitmapDescriptor generateBitmapDescriptorFromRes( | |
| Context context, int resId) { | |
| Drawable drawable = ContextCompat.getDrawable(context, resId); | |
| drawable.setBounds( | |
| 0, | |
| 0, | |
| drawable.getIntrinsicWidth(), | |
| drawable.getIntrinsicHeight()); | |
| Bitmap bitmap = Bitmap.createBitmap( | |
| drawable.getIntrinsicWidth(), |
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
| override fun start() { | |
| itemDBObservable = itemDao.getAllItems() | |
| compositeDisposable.clear() | |
| compositeDisposable += itemDBObservable | |
| .subscribeOn(Schedulers.io()) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .scan { previousList: List<Item>, newList: List<Item> -> | |
| val newItems = newList - previousList | |
| if (previousList.isNotEmpty() && newItems.isNotEmpty()) { | |
| showReturnToTopButton() |
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.layoutManager = object : | |
| LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { | |
| override fun onLayoutCompleted(state: RecyclerView.State?) { | |
| super.onLayoutCompleted(state) | |
| if (showReturnToTopButton | |
| && (findLastVisibleItemPosition() | |
| - findFirstVisibleItemPosition() | |
| + 1 | |
| < adapter.itemCount)) { | |
| buttonReturnToTop.visibility = View.VISIBLE |
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(object : RecyclerView.OnScrollListener() { | |
| override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) { | |
| super.onScrolled(recyclerView, dx, dy) | |
| if ((recyclerView?.layoutManager as LinearLayoutManager) | |
| .findFirstCompletelyVisibleItemPosition() == 0) { | |
| buttonReturnToTop.visibility = View.GONE | |
| } | |
| } | |
| }) |
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 createNotificationChannel() { | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
| val importance = NotificationManager.IMPORTANCE_DEFAULT | |
| val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, importance).apply { | |
| description = CHANNEL_DESCRIPTION | |
| } | |
| val notificationManager: NotificationManager = | |
| getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
| notificationManager.createNotificationChannel(channel) | |
| } |
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
| val builder = NotificationCompat.Builder(this, CHANNEL_ID) | |
| .setSmallIcon(R.drawable.ic_launcher_foreground) | |
| .setContentTitle("Interactive Notification Title") | |
| .setContentText("Interactive Notification Text") | |
| val notSoInteractiveNotification = builder.build() |
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 InteractiveNotificationBroadcastReceiver : BroadcastReceiver() { | |
| override fun onReceive(context: Context?, intent: Intent?) { | |
| Log.d("InteractiveNotificationBroadcastReceiver", "onReceive") | |
| } | |
| companion object { | |
| fun newPendingIntent(context: Context): PendingIntent { | |
| val intent = Intent(context, InteractiveNotificationBroadcastReceiver::class.java) | |
| return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) |