-
-
Save DivS-15/4f96ba11c85f84aaed2494f03c18f986 to your computer and use it in GitHub Desktop.
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
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity() { | |
private val TAG = "MainActivity" | |
private lateinit var auth: FirebaseAuth | |
private lateinit var binding: ActivityMainBinding | |
private val viewModel: MainViewModel by viewModels() | |
private val getContent = registerForActivityResult(MyOpenDocumentContract()) { uri: Uri? -> | |
// Handle the returned Uri | |
uri?.let { | |
onImageSelected(it) | |
} | |
Log.d(TAG, uri.toString()) | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
auth = Firebase.auth | |
auth.signInAnonymously() | |
val user = Firebase.auth.currentUser | |
binding.buttonSelectImage.setOnClickListener { | |
if (user != null){ | |
getContent.launch(arrayOf("image/*")) | |
} | |
} | |
} | |
private fun onImageSelected(uri: Uri){ | |
viewModel.uploadImageRequestBuilder(uri) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment