-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- UI improvements - Ability to use SDCard - Ability to share content - Code cleanup - Minor fixes & improvements
- Loading branch information
1 parent
20dd1d4
commit c7a3e94
Showing
60 changed files
with
843 additions
and
189 deletions.
There are no files selected for viewing
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 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 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
96 changes: 96 additions & 0 deletions
96
app/src/main/java/com/verNANDo57/rulebook_educational/app/CustomActivityResult.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Author: VerNANDo57 <[email protected]> | ||
*/ | ||
|
||
package com.verNANDo57.rulebook_educational.app; | ||
|
||
import android.content.Intent; | ||
|
||
import androidx.activity.result.ActivityResult; | ||
import androidx.activity.result.ActivityResultCaller; | ||
import androidx.activity.result.ActivityResultLauncher; | ||
import androidx.activity.result.contract.ActivityResultContract; | ||
import androidx.activity.result.contract.ActivityResultContracts; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class CustomActivityResult<Input, Result> { | ||
/** | ||
* Register activity result using a {@link ActivityResultContract} and an in-place activity result callback like | ||
* the default approach. You can still customise callback using {@link #launch(Object, OnActivityResult)}. | ||
*/ | ||
@NonNull | ||
public static <Input, Result> CustomActivityResult<Input, Result> registerForActivityResult( | ||
@NonNull ActivityResultCaller caller, | ||
@NonNull ActivityResultContract<Input, Result> contract, | ||
@Nullable OnActivityResult<Result> onActivityResult) { | ||
return new CustomActivityResult<>(caller, contract, onActivityResult); | ||
} | ||
|
||
/** | ||
* Same as {@link #registerForActivityResult(ActivityResultCaller, ActivityResultContract, OnActivityResult)} except | ||
* the last argument is set to {@code null}. | ||
*/ | ||
@NonNull | ||
public static <Input, Result> CustomActivityResult<Input, Result> registerForActivityResult( | ||
@NonNull ActivityResultCaller caller, | ||
@NonNull ActivityResultContract<Input, Result> contract) { | ||
return registerForActivityResult(caller, contract, null); | ||
} | ||
|
||
/** | ||
* Specialised method for launching new activities. | ||
*/ | ||
@NonNull | ||
public static CustomActivityResult<Intent, ActivityResult> registerActivityForResult( | ||
@NonNull ActivityResultCaller caller) { | ||
return registerForActivityResult(caller, new ActivityResultContracts.StartActivityForResult()); | ||
} | ||
|
||
/** | ||
* Callback interface | ||
*/ | ||
public interface OnActivityResult<O> { | ||
/** | ||
* Called after receiving a result from the target activity | ||
*/ | ||
void onActivityResult(O result); | ||
} | ||
|
||
private final ActivityResultLauncher<Input> launcher; | ||
@Nullable | ||
private OnActivityResult<Result> onActivityResult; | ||
|
||
private CustomActivityResult(@NonNull ActivityResultCaller caller, | ||
@NonNull ActivityResultContract<Input, Result> contract, | ||
@Nullable OnActivityResult<Result> onActivityResult) { | ||
this.onActivityResult = onActivityResult; | ||
this.launcher = caller.registerForActivityResult(contract, this::callOnActivityResult); | ||
} | ||
|
||
public void setOnActivityResult(@Nullable OnActivityResult<Result> onActivityResult) { | ||
this.onActivityResult = onActivityResult; | ||
} | ||
|
||
/** | ||
* Launch activity, same as {@link ActivityResultLauncher#launch(Object)} except that it allows a callback | ||
* executed after receiving a result from the target activity. | ||
*/ | ||
public void launch(Input input, @Nullable OnActivityResult<Result> onActivityResult) { | ||
if (onActivityResult != null) { | ||
this.onActivityResult = onActivityResult; | ||
} | ||
launcher.launch(input); | ||
} | ||
|
||
/** | ||
* Same as {@link #launch(Object, OnActivityResult)} with last parameter set to {@code null}. | ||
*/ | ||
public void launch(Input input) { | ||
launch(input, this.onActivityResult); | ||
} | ||
|
||
private void callOnActivityResult(Result result) { | ||
if (onActivityResult != null) onActivityResult.onActivityResult(result); | ||
} | ||
} |
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 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 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 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
Oops, something went wrong.