This file contains 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
... | |
//navigate to Sign Up screen to create a new user | |
buttonSignUp.setOnClickListener { view -> | |
view.findNavController().navigate(R.id.action_signInFragment_to_signUpFragment) | |
} | |
... |
This file contains 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
... | |
//check is there a signed in user and navigate to specific destination | |
if (usersRepositoty.userExists()) | |
Navigation.findNavController(view).navigate(R.id.action_splashFragment_to_messageListFragment) | |
} else { | |
Navigation.findNavController(view).navigate(R.id.action_splashFragment_to_signInFragment) | |
} |
This file contains 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"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<fragment | |
android:id="@+id/fragmentNavHost" | |
android:name="androidx.navigation.fragment.NavHostFragment" | |
android:layout_width="match_parent" |
This file contains 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
fun chainWorks(filter1: Work, filter2: Work, compress: Work, upload: Work) { | |
WorkManager.getInstance() | |
// Run these works in parallel | |
.beginWith(listOf(filter1, filter2)) | |
// Dependent work (only runs after all previous work in chain) | |
.then(compress) | |
.then(upload) | |
// Don't forget to enqueue() | |
.enqueue() | |
} |
This file contains 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
fun createConstraints() = Constraints.Builder() | |
.setRequiredNetworkType(NetworkType.UNMETERED) // if connected to WIFI | |
// other values(NOT_REQUIRED, CONNECTED, NOT_ROAMING, METERED) | |
.setRequiresBatteryNotLow(true) // if the battery is not low | |
.setRequiresStorageNotLow(true) // if the storage is not low | |
.build() | |
fun createWorkRequest(data: Data) = PeriodicWorkRequestBuilder<LocationWorker>(12, TimeUnit.HOURS) // setting period to 12 hours | |
// set input data for the work | |
.setInputData(data) |
This file contains 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 LocationWorker(context: Context, workerParams: WorkerParameters) | |
: Worker(context, workerParams) { | |
... | |
override fun doWork(): Result { | |
val latitude = inputData.getDouble(KEY_LATITUDE, 40.1903484) | |
val longitude = inputData.getDouble(KEY_LONGITUDE, 44.5148367) | |
This file contains 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 onCreate(savedInstanceState: Bundle?) { | |
// some smart stuff here | |
bottomAppBar.replaceMenu(R.menu.menu_wallpaper) | |
bottomAppBar.setNavigationOnClickListener { | |
// do something interesting on navigation click | |
} | |
} |