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
// workDataOf (part of KTX) converts a list of pairs to a [Data] object. | |
val imageData = workDataOf(Constants.KEY_IMAGE_URI to imageUriString) | |
val uploadWorkRequest = OneTimeWorkRequestBuilder<UploadWorker>() | |
.setInputData(imageData) | |
.build() |
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 UploadWorker(appContext: Context, workerParams: WorkerParameters) | |
: Worker(appContext, workerParams) { | |
override fun doWork(): Result { | |
try { | |
// Get the input | |
val imageUriInput = inputData.getString(Constants.KEY_IMAGE_URI) | |
// Do the work | |
val response = upload(imageUriInput) |
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
// -- Copy into dependencies block -- | |
// Room components | |
implementation "android.arch.persistence.room:runtime:1.1.1" | |
annotationProcessor "android.arch.persistence.room:compiler:1.1.1" | |
androidTestImplementation "android.arch.persistence.room:testing:1.1.1" | |
// Lifecycle components | |
implementation "android.arch.lifecycle:extensions:1.1.1" | |
annotationProcessor "android.arch.lifecycle:compiler:1.1.1" |
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
// The finished onCreate method | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mViewModel = ViewModelProviders.of(this).get(ScoreViewModel.class); | |
displayForTeamA(mViewModel.scoreTeamA); | |
displayForTeamB(mViewModel.scoreTeamB); | |
} |
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 | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mViewModel = ViewModelProviders.of(this).get(ScoreViewModel.class); | |
// Other setup code below... | |
} |
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
public class ScoreViewModel extends ViewModel { | |
// Tracks the score for Team A | |
public int scoreTeamA = 0; | |
// Tracks the score for Team B | |
public int scoreTeamB = 0; | |
} |
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
### GIT ENHANCEMENT START ### | |
# Git enhancement settings | |
unset GIT_PS1_SHOWSTASHSTATE | |
# Git enhancements | |
source ~/.git-completion.sh | |
source ~/.git-prompt.sh | |
# colors! | |
cyan=$(tput setaf 33) |
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
// This is the code showing how to get user input from and EditText | |
// First, use findViewById to get the EditText view (just like you would | |
// get any other view in the layout | |
EditText myEditText = (EditText) findViewById(R.id.send_edit_text); | |
// Then from the edit text, perform two actions, first to get the "Text", then | |
// to change it to a String. It is kind of silly that you can't just have one | |
// action "getString", but it is the way that the engineers of Android chose | |
// to make it so ¯\_(ツ)_/¯ |
NewerOlder